Monday, 04 May 2015 16:41

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.

Last modified on Monday, 04 May 2015 17:28
Comments (4)
This comment was minimized by the moderator on the site

Why not just use the standard front page template?

NancyDru
This comment was minimized by the moderator on the site

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...

Nate Covington
This comment was minimized by the moderator on the site

Hello

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

how can i do that

yane
This comment was minimized by the moderator on the site

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.

Nate Covington I
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Suggested Locations

Call or email today for a free consultation:

Monday - Friday 9-5 ET
570.508.6881
office@covingtoncreations.com

Latest Comments

Got a similar email that seemed suspicious. Ignored it and they even followed up today.
My organization received one of these emails from "Linda," but uses https://www.bestprosintown.com/p...
Hi Nate, I got the same email template from the same email address today and found you through a ...
Just received one today (16 Aug 2022) from "Mailchimp". Thanks for sharing!
Thanks for posting this. I just got one today. I was 99% sure it was a scam, and your post confirmed...


Design & Development

Wordpress, Drupal, Joomla
New custom websites
Bespoke themes and extensions
Redesigns, upgrades, migrations

Web Design & Development


Optimization & SEO

Let us optimize and manage your overall online presence. We offer full service monthly SEO as well as one-time projects.  

Optimization Plans & Pricing


Maintenance, Patching

White glove monthly backups, security updates, maintenance and testing for your Wordpress, Drupal, or Joomla site.

Maintenance Plans & Pricing


Email Newsletter

Bring your web & marketing performance to the next level: monthly blog post roundup via email.  

Stay in Touch!

Member

scranton chamber crop