Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I am looking for simple way to include footer.tpl.php that is just html block into another template like page.tpl.php. In Grails/Groovy that is as simple as

<g:render template="side_menu"/>

Is there a same simple way(preferred no use any panels, custom modules, etc) in Drupal? Thank You

share|improve this question

2 Answers

up vote 4 down vote accepted

The way to include another .tpl.php file is the include function.

Another idea is to add your footer as a region in the page.tpl.php and assign a region wise theme as defined in Drupal 7 Template (Theme Hook) Suggestions

region--[region].tpl.php The region template is used when a page region has content, either from the Block system or a function like hook_page_build(). Possible region names are determined by the > theme's .info file.

share|improve this answer
Thank you Nikhil. Per your suggestions, i created region such as 'footer', put the block code into block--footer.tpl.php file. Afterwards, rendered it within any template by "print render($page['footer'])" – latvian May 12 at 14:22
Well..there is a problem with "render($page['footer'])". Drupal only calls for 'block--footer.tpl.php' region template if there is a block assigned to this region from the admin portal. – latvian May 12 at 15:33
I end up using include as follows: <?php include './'. path_to_theme() .'/templates/block--footer.tpl.php';?> – latvian May 12 at 15:34

If your drupal site do not call for region--[region].tpl.php file, then check your template.php file and find preprocess_region function:

/**
 * Override or insert variables into the region templates.
 *
 * @param $variables
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("region" in this case.)
 */

function YOURTHEME_preprocess_region(&$variables, $hook) {
  // add theme suggestions for blockgroup region
  if (strpos($variables['region'],'blockgroup') === 0) {
    $region_name = str_replace(array(' ','-'), '_', $variables['region']);
    $variables['theme_hook_suggestions'][] = 'region__'.$region_name;
  }
}

* This function should be there. If not, just place it.

In your region--footer.tpl.php file:

/**
 * @file
 * theme implementation to display a region footer
 * variables:
 * - $content: The content for this region, typically blocks.
 * - $classes: String of classes that can be used to style contextually through CSS
 * - $region: The name of the region variable as defined in the theme's .info file.
 * - $classes_array: Array of html class attribute values. It is flattened into a string within the variable $classes.
 * - $is_admin: Flags true when the current user is an administrator.
 * - $is_front: Flags true when presented in the front page.
 * - $logged_in: Flags true when the current user is a logged-in member.
 */
?>

<?php if ($content): ?>
  <div class="your_region_class">

      <?php print $content; ?>

  </div><!-- /.region -->
<?php endif; ?>

* read comments

share|improve this answer
Jack, you are right the preprocessor method is missing in template.php. I will come try this out at later time as i have move forward with the 'include'. Thank You – latvian May 13 at 12:41
You're welcome. I'm glad I could help. – Jack-PL May 13 at 13:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.