Skip to content

Instantly share code, notes, and snippets.

@matiskay
Created December 17, 2011 03:28
Show Gist options
  • Save matiskay/1489044 to your computer and use it in GitHub Desktop.
Save matiskay/1489044 to your computer and use it in GitHub Desktop.
A basic scaffold to use hook_theme.

Basic scaffold to use hook_theme

You need to create a file called template-name.tpl.php in templates directory. Don't forget to run drush cc all, the Drupal caching system could play with your.

<?php
/**
* Implements hook_theme().
*
* Defines the theming capabilities provided by this module.
*/
function my_module_theme() {
return array(
'template_name' => array(
// In this one the rendering will be done by a tpl.php file instead of
// being rendered by a function, so we specify a template.
'template' => 'templates/template-name',
'variables' => array('node' => NULL),
),
);
}
function my_module_render($node) {
$output = '';
$output .= theme('template_name', array('node' => $node));
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment