I created a diagram outlining the issues here: http://www.erality.com/assets/link/phptemplatevars.gif
Ultimate goal:
Specify different node templates for pages (i.e. node/5) and blocks (i.e. nodes being retrieved for blocks [recent posts, etc]).
Summary
For the site I am working on, I will need to create a number of custom blocks. These blocks will be using node content in output. For example, a "recent posts" block. However, I am unable to specify which node template to use when a block retrieves nodes.
Attempt: I tried using phptemplate_variables(), however, was unsuccessful at determining whether the requested node was for a block or page (see code below) . The $hook variable is set to 'node' when a block retrieves a node.
Possible solution: Is a way to know if a node is being retrieved for a block or a page in the phptemplate_variables() function? Is this the wrong approach?
Any help would be greatly appreciated.
function _phptemplate_variables($hook, $vars) {
switch($hook) {
case "node":
$suggestions[] = 'nodePage';
$vars['template_files'] = $suggestions;
break;
}
return $vars;
}
Comments
How do you populate the
How do you populate the block with the nodes?
In this case I am using
In this case I am using views, however, some of the blocks will be created outside of views.
You can theme the view (see:
You can theme the view (see: http://drupal.org/node/42597). Here is a general solution assume you have a full node or teaser node view.
When theming the node (in node.tpl.php for example) you could them check to see if $node->view_build_type iis equal to 'block'.
If you only want this information for one view you can change phptemplate_views_view_nodes() to phptemplate_views_view_nodes_VIEWNAME() replacing VIEWNAME with the name of your view.
Sweet. That looks like it
Sweet. That looks like it solves the problem if I am using views. However, some of the blocks I will be creating will be made outside of views. How do I solve the problem then?
In case where you have
In case where you have something like
You add add fields to $node like in the above example.
Ah, pass a custom value.
Ah, pass a custom value. Righto, thanks for the help.