Easy Node Customization

Printer-friendly versionPDF version

Drupal has an awesome customization feature that not too many new people seem to know about. You can customize just about any view by creating a special template file for that view.

For Example:

Let's say that you want to update the front page layout. What you need to do is create a custom template file for the front page. Drupal themes have template files for each node type. If you look in your theme directory you should see files like node.tpl.php and page.tpl.php. These files describe the layout for nodes (like blog posts) and pages respectively.

Open the page.tpl.php file. Then save the file as page-front.tpl.php. Congratulations, you have just created a custom theme file for the front page of your site. When you edit the contents of that file and upload it to your theme directory the layout in that file will apply only to the front page of your site.

If you want to create a custom theme file for only blog posts you would take the same steps as described above but with node.tpl.php. You would change the name of the theme file to node-blog.tpl.php. This will work for any custom node type you create using CCK. Just replace the word 'blog' with the name of the new content type you have created.

At this point you might be asking, "What types of changes can I make to these files?" Good question. Editing the tpl.php files makes sense when you are looking to add features not already implemented by a module. For example, I've used this technique to add the AddThis bookmarking widget to only blog nodes.

You can also use this technique to change the layout or remove certain elements of a node. For example, you can add, remove or move the links to categories or 'submitted by' information. In order to get more familiar with how you can use this technique I recommend that you work with a test site, make some changes to the custom theme files and see how that affects the look of your nodes once you've uploaded the changes.

Bookmark and Share Bookmark or Share Post

Comments

Anonymous's picture

Would this be the way you

Would this be the way you would suggest to have a 3-column front page even though the rest of the site is 2-column?

learnbythedrop's picture

It's One Way To Do It

You could certainly achieve three columns on the front page by editing the theme file, but you don't have to do it that way.

If your Drupal theme allows for two side bars (and most do I believe) then you could also simply set up your blocks so that you have blocks in two side bars on the front page while all other pages have blocks in only one sidebar.

You can set that up by selecting show only on the listed pages and indicating front in the pages section of block configuration.

Alternatively you could use the panels module to achieve a similar solution. Panels is not year ready for Drupal 6 though.

Anonymous's picture

well well well

What he said but only one nuance... It's actually .

Thank you come again.

Anonymous's picture

Thanks very much

Wow, I can't believe it took me this long to find this out, this would of eliminated a lot of my frustrations with Drupal. This makes it so simple to edit layouts of specific pages. Thanks!

Post new comment

Important
All comments on this site are moderated to prevent spam. Although we also use the Mollom module we have found that some gets through and that also affects people who have subscribed to email notifications. If you would like your comment to appear immediately please login with Google Friend Connect which supports your Google, Twitter or Yahoo account.
Google Friend Connect (leave a quick comment)
Loading
The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.