I have a page.tpl.php and I want to customize a section of the html so that it displays specific info for each page.

So, in a certain div, I want specific information related to that page to show.

My current solution is this:
In my template.php, just have a large switch statement that depends on the filepath. This then passes a template variable w/ my page specific info to page.tpl.php.

So, every time I add a page, I'll have to add another statement in the switch clause.

This just seems so inelegant, there must be a better way that I just can't think of right now.

Any suggestions? Is there some feature of drupal I'm overlooking?

Comments

alan d.’s picture

It looks like some form of switch is required somewhere even if you move the logic out into a module. (Using hook_node_api($op = 'view'); )

A dynamic solution is something like:

<?php
// added anywhere that is included:
function page_my_information_div($node) {
  return 'hello world';
}

// In the template
$func = $node->type . '_my_information_div';
if (function_exists($func)) {
  print $func($node);
}

// or preprocess / node_api($op = view) to prepopulate the $variable or $node->content array

?>

Harder, but even cleaner, is to add a custom FAPI field to the content type form. I would not be surprised to find a module that does this already.


Alan Davison
nevets’s picture

If the relation can be used by views and the information you want to display is available to views you could make a view that takes one argument (you will need to set default handling) and has a block display that you could then enable in a region.

jaypan’s picture

You could also create a block with php enabled for the input format, and set your logic in there. It would save having to re-upload your template.php file every time you create a page - you can just edit the block through the admin interface.

Contact me to contract me for D7 -> D10/11 migrations.

alan d.’s picture

Apparently, http://drupal.org/project/context also can be configured to do this. I haven't used it personally.


Alan Davison