views:

208

answers:

3

Hi friends,

I'm a drupal newbie...

I have different type of contents like News, Events, etc. and their content is different. News detail page has title-content text-date. but Events detail page has title-date-content text-location-speaker-etc. So I need different layout page for these different types. So, I enabled Drupal Themer to get a candidate name. for events page, it gave me page-node.tpl.php and it gives same for News page as well :( how can I separate these pages? I expected sth like page-event-node.tpl , but no... :/ Drupal Themer also give unique candidate name for event page like page-node-18.tpl.php but it doesnt mean anything since I can not create a general layout for all events by this node name. :(

Appreciate helps so much!! Thanks a lot!!!

+2  A: 

I'm not familiar with Drupal Themer, but a slightly different approach would be to work with the node templates to style the content and use something like the excellent Context module (and possibly Panels module) to change the layout of any additional information on the page (eg the blocks).

To theme the different content types using node templates, just create templates based on node.tpl.php in the form node-content_type.tpl.php. So you'd have a template for your events nodes called node-events.tpl.php.

You could then define a context using the Context module that reacted when a page of the events content type was displayed and select which regions/blocks you wanted displayed.

monkeyninja
thanks for reply... node.tpl.php contains only content part, but for this event detail page I need to specify sidebar, footer, etc as well. That's why I've been looking for a page-node.tpl.php solution. So I'm going to review the Context Module now, thanks!
artmania
The Context module is well worth getting to grips with as it gives much better control over blocks on a site and introduces the more common idea of "sections" to a Drupal site.
monkeyninja
ps, thanks for mentioning Context module. I'm going to use that for next projects. thanks a lot! :)
artmania
+3  A: 

While using different node.tpl.php files as suggested by monkeyninja (+1) would be the 'normal' way, you could add the functionality you want by adding page template suggestions based on node type yourself, in a preprocess_page function within a custom module/theme:

function yourModuleOrTheme_preprocess_page(&$variables) {
  // If this is a node page, add a page template suggestion based on node type
  if (isset($variables['node'])) {
    // Build the suggestion name ('.tpl.php' suffix will be added by the theming system)
    $suggestion = 'page-type-' . $variables['node']->type;
    // Add to end of suggestion array, thus keeping the fallback to other suggestions,
    // if this specific version is not implemented by the theme
    $variables['template_files'][] = $suggestion;
  }
} 

With this in place, you should be able to add e.g. a 'page-type-event.tpl.php' file, which should be used for all event node pages.

(NOTE: You'll need to trigger a rebuild of the theme registry after adding that function to get it recognized by the system)

Henrik Opel
wow! thanks for reply! it looks good for my solution... so I add this function to themes/mysite/template.php and how can use it to define page-type-event.tpl.php to the event pages? ps, thanks for the link http://drupal.org/node/223430 I'm reading all.
artmania
wowowow you are the master!!! forgot to clear cache, now it works so great!! now i have page-type-event.tpl.php !! thanks man! I mean it!! I would love to buy you a beer or anything... :)
artmania
Glad to have helped - a word of warning, though: Multiplying your page templates excessively can be quite a maintenance burden down the road, as you'll end up with multiple places you need to keep in sync for basic stuff that should be the same throughout a site. So you might still want to explore alternative solutions like the suggested context module, or switching block visibility based on node types, etc...
Henrik Opel
thanks for the warning. today is deadline for the project. and I know how to shape content with $node->fields... I can quickly complete. I will review context module later when i have time, for next project :) thanks again.
artmania