0

I have a view which is modified by a views template page - this is in Drupal 6.

I'm trying to figure out a condition to affect the layout. Currently, the element seems to be generated in page.tpl.php, which is fine, but I want to add a condition for this specific page, in order to add an id to this element.

For other pages, I've used the node id to do this, as such:

else if ($node->nid == '250' || $node->nid == '429' || $node->nid == '555' || $node->nid == '378') {print '<h1'. ($tabs ? ' class="with-tabs"' : '') .' id="medspecheader">'. $title .'</h1>';}

But I'm not sure how to do this with the view page. Is there a machine name that I can use, or something to affect the layout?

1 Answer 1

0

If you are asking how to modify the default page.tpl.php to do something different when a specific path is called, you could just copy page.tpl.php to page-PATH.tpl.php, eg, page-PATH-THAT-VIEWS-USES.tpl.php and then anything inside this new template would be used just for the page displayed at that path.

In your example code, as an example, you could copy page.tpl.php to page-node-250.tpl.php or page-node-429.tpl.php etc and then you wouldn't need any ifs in them with respect to the id="medspecheader" as these templates would only be used when looking at those nodes.

Just realize that the path used is the drupal system path, not any alias, but Views does create such a path for any Views that utilize a Page Display.

Lots more information about template suggestions for Drupal 6 can be found here.

If these don't work for your specific needs, you can also create more templates suggestions for Drupal to use via a hook_preprocess_page() call in your module or theme.

For example, if you wanted the page to display differently whenever a specific node type is being displayed, and you didn't want to hard code in all of the specific node nids, you could do something like this in your theme...

function YOURTHEME_preprocess_page(&$variables) {

  if (isset($variables['node']) && $variables['node']->type=='med_special') {
    $variables['template_files'][]='page-cck-' . str_replace('_','-', $variables['node']->type);
  }

  // any other page preprocessing goes here

}

Now, whenever page displaying a node of type med_special is called up, Drupal will look for a page-cck-med-special.tpl.php file in your theme to display it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.