code
Drupal staging and deployment tips: It’s all code | sacha chua :: living an awesome life
What are the best practices for rendering different types of node displays?
The following post is an answer I wrote to a question submitted to Tree House Agency in preparation for Do It With Drupal (New Orleans 2008). Tree House has kindly given me permission to post this material on my own website.
Q: One node, varied displays?
BH asks:
What are the best practices for rendering different types of node displays?
Short Answer
Three methods immediately come to mind. These are:
1. Different TPL files for each type of node
2. Switching template files by path
3. Using CSS to change display by node type
Additional cases may include:
4. Switching by taxonomy term
5. Switching by role type
6. Switching by user id
Details
1. Different TPL files for each type of node
Drupal already has an excellent built in method for rendering different types of node displays.
Grab a copy of node.tpl.php from Drupal’s modules/node/ directory.
![clip_image002[8] clip_image002[8]](http://www.seanbuscay.com/sites/default/files/clip_image002%5B8%5D_eb42d4ce-7e4a-4a8f-845b-511bc02c8f31.jpg)
Put it into your site theme folder. Then rename it according to whatever node type you would like to customize. (node-nodetype.tpl.php )
Notes:
The node type should be the machine readable content type.
There are many places to find the machine readable name. One place is at: /admin/content/types
Dev snapshot of a CMS I wrote
The following are samples of database work I have done. I have attached a sql file as a sample. It is a dev snapshot of a CMS I wrote.
So you don’t have to just stare at sql statements, I have highlighted some points in this post. I will paste sections of the sql statements and then comment on them.
More about my theme for SeanBuscay.com.
I built a Drupal theme I call “chi”. It is based on the Yahoo! YUI Grids CSS foundation. Like the excellent “Zen” theme already written for Drupal, a Drupal theme based on Yahoo! grids CSS can offer an excellent starter theme for Drupal developers and themers.
I recently posted a summary on the benefits of YUI Grids CSS for Drupal theme developers on my blog. You can view it as a screencast, PowerPoint presentation, read a text summary, or download a PDF from this URL:
http://seanbuscay.com/drupal-web-development/yahoo-ui-library-grids-css-drupal-themers
I have included a zip file of the theme code at the end of this post for you to review.
I’ll highlight a few sections of the code and features in the screen shots below.
First, this is a Drupal 6 theme, which utilizes an .info files for themes. A number of theme elements can now be defined within a simple text based .info file rather than within the code of a template.php file. Here’s a screenshot of the included chi.info file.
Note that regions and theme style sheets may be defined in the theme.info file. One important catch is to define the CSS files in the order in which you would like them to load. They are like defining an array in PHP or Java. So, when including a file sheet which resets all fonts and html elements to a base starting point, and then including a style sheet which builds upon that base reset, the load order needs to be considered.
Inline Tags Sample Module Code
/**
* Module implementing Drupal's hook_nodeapi
* @see http://api.drupal.org/api/function/hook_nodeapi/6
* Important Note: This is sample code.