Undefined index render element

In Drupal 7 (I’m running version 7.26 at the moment), if you receive the following error…

Notice: Undefined index: render element in theme() (line 1081 of /home/bn/brighternet/clients/mmh/dev/website/drupal/includes/theme.inc).

…then you probably forgot to define the ‘variables’ or ‘render element’ key in the nested array that you return from your implementation of hook_theme() in your theme’s template.php.

See the ‘Return value’ section in Drupal’s documentation about hook_theme.

For example, you’ll get the error from the following code (in [drupal]/sites/all/themes/my_theme/template.php) if you remove the ‘variables’ key:

/**
 * Implementation of hook_theme() to register templates for this theme.
 */
function my_theme_theme($existing, $type, $theme, $path) {
  return array('template_test' => array('variables' => array(), // We need the 'variables' key to prevent 'Undefined index: render element ...' warning.
                                'path' => drupal_get_path('theme', 'my_theme').'/templates',
                                'template' => 'template_test'));
}

Last modified: 19/02/2014 Tags: ,

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top