2

I'm currently building my first Drupal theme (have experience in other content manager systems) and just have a quick question regarding normal practice...

So, I have a number of different templates for a website theme I am building

Home > Level 1 > Level 2 > Article

I have created Content Types for each of the different templates e.g

*node--level_1.tpl.php*, *node--level_2.tpl.php*

By default it seems that the page's title is printed in page.tpl.php.

My plan is to delete the title from page.tpl.php and render it where appropriate within the node templates.

My question is simply is this ok? Is this normal practice? And are there any implications/consequences of doing this?

It's worth saying the reason for doing this is that on some levels there is no title, and often when the title exists it has to rendered under an image (so printed under the custom image field).

Obviously one issue I instantly thought of is that for default pages such as /user the title won't be printed. Could I use some logic in page.tpl.php to say print the page title only if it is not printed within the content type node template?

Thanks for your time!

Scott

4

I'd say go ahead - your plan to remove the Title from the page template and print it instead in the node template makes sense to me. I've done similar things in the past.

One thing you may want to look into is creating a custom page template for your content types, in addition to your node templates. This will give you even more control over your final rendered page on a per-content-type basis. This could help you avoid inadvertently removing the title from other pages, eg. your Front page.

Here's a quick function you can add to your theme's template.php file that will get Drupal to look for a custom page template (eg. *page_node_yourcontenttype* for each content type.

/**
* Tell Drupal 7 to look for a custom page template for each node type. 
*/
function YOUR_THEME_NAME_preprocess_page(&$vars, $hook) {
    if (isset($vars['node'])) {
        $suggest = "page__node__{$vars['node']->type}";
        $vars['theme_hook_suggestions'][] = $suggest;
    }
}

Please note that I didn't write this particular snippet, but I have done the exact same thing successfully. Check out http://leepowers.net/drupal-node-custom-content-type-page-template (not my site) for the original snippet with a nice explanation.

Hope that helps!

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.