Skip to content

Instantly share code, notes, and snippets.

@axooh
Created August 19, 2012 09:39
Show Gist options
  • Save axooh/3393980 to your computer and use it in GitHub Desktop.
Save axooh/3393980 to your computer and use it in GitHub Desktop.
Drupal Preprocess Node
<?php
/**
* Override or insert variables into the node templates.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("node" in this case.)
*/
function theme_preprocess_node(&$variables, $hook) {
// Split Node view modes into separate template files (e.g. node--basic_element--teaser.tpl.php)
$variables['theme_hook_suggestions'][] = 'node__' . $variables['type'] . '__' . $variables['view_mode'];
// Optionally, run node-type-specific preprocess functions, like
// theme_preprocess_node_page() or theme_preprocess_node_story().
$function = __FUNCTION__ . '_' . $variables['node']->type;
if (function_exists($function)) {
$function($variables, $hook);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment