Monday, 04 May 2015 16:41

Drupal theming: front page block positions

Written by 
Drupal theming: front page block positions

A Discussion Drupal vs Joomla Theming

I think this might be my first post specifically about Drupal.  I’ve been using Drupal for a few years now, but as many know, I’ve been a Joomla guy for a lot longer.  One of the nice things about Drupal’s theming structure is their “content” is rendered as a regular block.  So, when you’re managing blocks in the admin panel, you can assign a contact form block to the content area block area, and it shows up right below it.  No need to tweak the template files create a new block area (in Joomla speak, a module position).

Let’s look at the code

This is what comes by default in your Drupal theme page.tpl.php template:

    <h1><?php print render($title); ?></h1>
    <?php print render($page['content']); ?>

This implies that all of your pages will be structured the same, with the title and content.

In some projects, I’ve written code like this, which determines whether it is the home page or not, then render the content blocks based on the answer.  You’ll see in my code, the front page will load the “homecontent” blocks.  The inside pages will render the page title first, then the standard “content” position.

I’ve written this so that it’s easy to add block areas or set up DIV’s around them for various CSS techniques.  Keep in mind that you can also use the “body.front” CSS prefix to single out the home page directly in your CSS, which is often a cleaner solution than below, depending on what you’re trying to achieve.

<?php if ($is_front): ?>
<?php print render($page['homecontent']); ?>
<?php endif; ?>

<?php if (!$is_front): ?>
    <h1><?php print render($title); ?></h1>
    <?php print render($page['content']); ?>
<?php endif; ?>

I hope this is helpful!  As always, if you know of a better way of doing something, please sound off in the comments below.  Likewise if you have a request for a different topic or tutorial.

Read 4813 times Last modified on Monday, 04 May 2015 17:28


  • Comment Link Nate Covington I Friday, 07 December 2018 19:05 posted by Nate Covington I

    Edit the "user menu block" and change it to a different theme position - save. Note that the theme positions are determined by each specific template - so if yours is hand coded you might need to add another theme position first.

  • Comment Link yane Friday, 07 December 2018 16:56 posted by yane


    i want to change the region of my user menu ..

    how can i do that

  • Comment Link Nate Covington Thursday, 07 May 2015 16:19 posted by Nate Covington

    In some cases, I'd rather not have a totally separate file for the front page template. There is more than one way to skin a cat...

  • Comment Link NancyDru Tuesday, 05 May 2015 22:09 posted by NancyDru

    Why not just use the standard front page template?

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.