Search code examples
drupaldrupal-6content-typedrupal-theming

Drupal 6: Drupal Themer gives same candidate name for different type of content types


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!!!


Solution

  • 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)