Jody's blog
Fun with Theme Switching
Posted June 17th, 2008 by JodyUPDATE: CODE REWORKED THANKS TO CHX
<?php
/**
* Implementation of hook_menu (D5 code)
*/
function SOMEMODULE_menu($may_cache) {
if (!$may_cache) {
if ($theme = $_GET['theme']) {
$themes = list_themes();
if (isset($themes[$theme])) {
$GLOBALS['custom_theme'] = $theme;
}
}
}
}
?>With this you can amuse yourself by browsing to /node/1?theme=marvin
I was thinking this could actually be useful- for example you could make an all xml theme and have Flash get data from path/to/page?theme=xml_theme
Drupal Node Access Explained
Posted June 11th, 2008 by JodyDrupal's API contains a pretty good description of how node access works (developers should also analyze the node_access function itself). There are many contributed node access control modules for Drupal and you really should understand the basics of node access before installing and configuring one. The API should suffice for developers but for the benefit of our many community members who build sites without reading code, here is a translation and some basic rules of thumb:
HowTo: Add a freetagging form to a node display (Drupal 5)
Posted April 23rd, 2008 by JodyThis has been added to the Drupal 5 PHP Snippet section of the Drupal Handbook
I needed to make a little freetagging form to allow users to tag content as they view it - here's how I did it:
Set up a freetagging vocabulary using taxonomy.module and assign it to your content type as usual. Note the vid (vocabulary id) of your freetagging vocabulary (you can find it in the URL when editing the vocabulary). In a custom module, create a new form like so:
<?php
// form for adding tags to nodes
function MY_CUSTOM_MODULE_tag_form($nid = 0) {
$form = array();
$form['nid'] = array(
'#type' => 'hidden',
'#value' => $nid,
);
$form['tag'] = array(
'#type' => 'textfield',
'#title' => 'add tag',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('+'),
);
return $form;
}
?>A simple shell command for drupal cvs checkouts
Posted April 19th, 2008 by Jody#!/bin/bash
cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -r DRUPAL-$2 -d $1 contributions/modules/$1There are lots of great Drupal productivity / development modules (e.g. drush, devel, coder) which due to their nature as modules need to be installed on each site you work on. If you work on a dizzying number of different Drupal sites, productivity improvements which are not site-specific are the most useful.
NB: this post is geared toward Mac users.
File-Based Content Templates
Posted April 10th, 2008 by JodyJohn Forsythe recently posted that Contemplate is one of the most favorited modules on his DrupalModules.com site, attributable to the learning curve of creating template files.
With no offense to Jeff Robbins who created this very clever module, I've never been a big fan of Contemplate. I don't like it when people store code and markup in the database because it makes it impossible for me to find where their markup comes from when I search the files. It also puts it out of the reach of version control, and creates the possibility of a white-screen situation which can only be fixed by going into the database directly.
But contemplate fills a real void created by the difficulty in per-field theming in Drupal 5. I posted about my method of handling per-field theming in content types recently and have been refining that method since. The purpose of my technique is to allow per-field custom theming without requiring additional work every time a new field is added. Essentially you print out any fields you would like to custom theme, and then you loop through all the other fields and print them all out in the order and with the 'Display Fields' settings as set in CCK. Although this method requires additional setup up front, it pays off when you add new fields (or modules that add new node content of their own) and you don't have to readjust your template (or contemplate).



