1

This is probably (hopefully) a simple question, but I can't figure it out: I'm trying to customize a theme to add a div/region for a "banner" that will display the title of the page on each page...except for the front page. The front page will have a similar "banner" but with different content, more like a promotional thing.

I thought the simplest way to include the banner with the title was simply to move the title rendering in the page.tpl.php:

  <div id="banner"><div class="section clearfix">
      <?php print render($title_prefix); ?>
      <?php if ($title): ?>
        <h1 class="title" id="page-title">
          <?php print $title; ?>
        </h1>
      <?php endif; ?>
      <?php print render($title_suffix); ?>
  </div></div> 

This works fine, but then I will get it on the front page as well, and there I want it replaced by a similar banner but with custom content, preferably inserted by a custom block I will create.

How do I do this separately for the home/front page?

3

You can differentiate a front page using drupal_is_front() API

<?php if(!drupal_is_front_page()):?>
 <div id="banner"><div class="section clearfix">
      <?php print render($title_prefix); ?>
      <?php if ($title): ?>
        <h1 class="title" id="page-title">
          <?php print $title; ?>
        </h1>
      <?php endif; ?>
      <?php print render($title_suffix); ?>
  </div></div> 
<?php endif;?>

Or you can create a new TPL page-front.tpl.php and omit this div element in that TPL so that it never gets printed. This TPL will be used for front page only.

  • Ok, thanks. I think I like the first idea better. But in case I were to go with a separate template for the front, where do I specify that the front page should use that template? – Anders Svensson Jul 19 '12 at 9:30
  • Just put the new file in your theme folder and drupal will pick it up (i.e once you clear cache and visit admin/build/themes) – GoodSp33d Jul 19 '12 at 9:32
  • Ok, I just tried the first suggestion though, and when using it (with or without exclamation mark for is drupal front or is not drupal front, but either way I got a completely unstyled page as a result... so something must have gone wrong with the conditional here... – Anders Svensson Jul 19 '12 at 9:33
  • Ok i think your css depends on banner and some other IDs that are not getting printed modify if($title) like if($title && !drupal_is_front()) so that some divs gets printed and remove condition at top and last endif – GoodSp33d Jul 19 '12 at 9:36
  • Sorry, that didn't work. In fact, even this causes the problem: <?php if(!drupal_is_front()):?> <?php endif;?> – Anders Svensson Jul 19 '12 at 9:55
3

You can create a page--front.tpl.php file in your theme. This file is the same as page.tpl.php but only for the front.

Remember clear cache after the creation of the file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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