There is a folder called /theme and I created a file called example-theme.theme.inc inside of it with a function MYSUBTHEME_example_theme($variables). Where do I put the MYSUBTHEME_theme function to register it?

Comments

Adam S’s picture

Priority: Normal » Minor
Status: Active » Closed (fixed)

In the subtheme's template.php define the theme function.

/**
 * Implements hook_theme().
 */
function THEME_theme() {
  return array(
    'something' => array(
      'file' => 'theme/something.theme.inc',
      'variables' => array(),
    ),
  );
}

In the subtheme's /theme folder create a file called something.theme.inc. Then place the theme function inside that file.

<?php

function THEME_something($variables) {
  return '<ul class="duh" role="navigation">' . $variables['tree'] . '</ul>';
}

For an example of use, in the subtheme's page.preprocess.inc file located in the preprocess folder work some magic by overriding a core theme's output.

/**
 * Implements hook_preprocess_page().
 */
function THEME_preprocess_page(&$variables) {
  $variables['search_box'] = drupal_get_form('search_block_form');  
  
  // Get the entire main menu tree
  $main_menu_tree = menu_tree_all_data('main-menu');

  // Add the rendered output to the $main_menu_expanded variable
  $variables['main_menu_expanded'] = menu_tree_output($main_menu_tree);
  $variables['main_menu_expanded']['#theme_wrappers'] = array('something');
  
}

** Sorry to clutter the issue queue **