Theming the node
If you want your theme to be easy to understand and to locate the tpl files you will need to order them in folders.
The best choice is to separate them by node, field, block, view and other folders. So your node.tpl.php files will be located in the templates/nodes folder for example.
Another way to improve your node tpl files is separating them by node type. If you want to theme the blog nodes you will need to create a node--blog.tpl.php file and make your changes in it.
On the other hand, if you want to theme the node full view and the node teaser view of your blog nodes you could do it on the same node--blog.tpl.php file or separate them in two files:
- node--blog.tpl.php - for the node full view
- node--blog--teaser.tpl.php - for the node teaser view
You will only need to add the following implementation of template_preprocess_node to your template.php file replacing my_theme with the name of your theme:
/*** Implements template_preprocess_node()* Divide node full and teaser views in two tpls*/function my_theme_preprocess_node(&$vars){if ($vars['view_mode'] == 'teaser' && $vars['node']->type == 'blog') {$vars['theme_hook_suggestions'][] = 'node__blog__teaser';}}
Also you could do the same for all the node types of your site with this simple snippet:
/*** Implements template_preprocess_node()* Divide node full and teaser views in two tpls*/function my_theme_preprocess_node(&$vars) { $vars['theme_hook_suggestions'][] = 'node__' . $vars['node']->type . '__' . $vars['view_mode']; }



Post new comment