Reputation: 869
the site I'm currently building in Drupal is split into two very different areas, both structured quite differently. My solution is to build two different page.tpl pages. Does anyone know what the easiest method is to implement this in Drupal 7. Is it a naming convention process like the node.tpl page or will I need to insert a preprocess function in the template.php page.
Cheers for any help!
Upvotes: 0
Views: 2074
Reputation: 61
function your_theme_preprocess_node(&$variables) {
// Add specific templates.
foreach ($variables['theme_hook_suggestions'] as $theme_suggestion) {
$variables['theme_hook_suggestions'][] = $theme_suggestion . '__' . $node->view_mode;
}
}
also you can call preprocess function here if adding this code
// Run specific preprocess function.
$preprocess = 'your_theme_preprocess_node_' . $node->type . '__' . $node->view_mode;
if (function_exists($preprocess)) {
$preprocess($variables);
}
in this case you can use different templates not only for node types but for different view modes too
Upvotes: 0
Reputation: 2886
You can use the Context module.
Within a given context, you can add the "Template suggestions" reaction. This will allow you to specify additional template files that will override the defaults. See the issue in the Context queue, Add a "Template suggestions" reaction, for details.
With this approach, it's not necessary to write any module code.
Upvotes: 0
Reputation: 2587
I don't get it . If you want to use two different template files then just create two different content types and you can by pass all this coding.
let me know if you need further help. vishal
Upvotes: 0
Reputation: 448
You could also attach a preprocess function in your template.php file. Something like the following:
function yourthemename_preprocess_page(&$vars, $hook) {
if (isset($vars['node'])) {
// If the node type is "blog_madness" the template suggestion will be "page--blog-madness.tpl.php".
$vars['theme_hook_suggestions'][] = 'page__'. $vars['node']->type;
}
}
Upvotes: 3
Reputation: 28124
Have a look at this page: http://drupal.org/node/1089656
It explains the naming schema for your template files and how to extend the template suggestions.
In your case, you'll have to implement the theme_get_suggestions()
function. In this function you can check the path arguments to determine which kind of page you need to display and add the appropriate suggestions.
Upvotes: 1