Skip to content

Instantly share code, notes, and snippets.

@wesruv wesruv/gist:9469693
Last active Aug 29, 2015

Embed
What would you like to do?
Dynamic Drupal page preprocessors for taxonomies
function TEMPLATE_preprocess_page(&$variables) {
// Set some vars for ease
$node = isset($variables['node']) ? $variables['node'] : '';
$page = &$variables['page'];
// The good bit:
if(arg(0) == 'taxonomy') {
// Preprocess because it's a taxonomy
$function = __FUNCTION__ .'_taxonomy';
if(function_exists($function)) {
$function($variables);
}
if(arg(1) == 'term') {
$tid = arg(2);
$term = taxonomy_term_load($tid);
$vocabulary = $term->vocabulary_machine_name;
$variables['term'] = $term;
// Preprocess because it's a term
$function = __FUNCTION__ .'_term';
if(function_exists($function)) {
$function($variables);
}
// Preprocess because it's a term in a certain vocab
$function = __FUNCTION__ .'_term_'. $vocabulary;
if(function_exists($function)) {
$function($variables);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.