Agaric Design Collective

Print information associated with a node elsewhere in page.tpl.php, using a separate template file for theming

By Benjamin Melançon
on 28 Oct
0 comments

Key words and phrases

drupal call template file from template.php

Tags

Description

Thanks to a little refresher on the _phptemplate_callback function (replaced in Drupal 6's theming system with the theme registry) from searching Nick Lewis' site.

<?php
function _phptemplate_variables($hook, $vars = array()) {
  if (
$hook == 'page') {
    if (
$vars['node'] && arg(2) != 'edit') {
     
$vars['brandbar'] = _phptemplate_callback('brandbar', array('node' => $vars['node']));
    }
// ...
}
?>

That didn't give us the variables with the same values, in the same formats, we were used to getting them in the node.tpl.php, however. So we called on the patented (no, not really) Agaric way of loading nodes for a template file the same way they get presented to node.tpl.

This is the result (also we added filtering by node type to the if statement), not including the full agaric_node_load_view function which of course also must be in template.php or otherwise available:

<?php
function _phptemplate_variables($hook, $vars = array()) {
  if (
$hook == 'page') {
    if (
$vars['node'] && arg(2) != 'edit' && $vars['node']->type == 'partner') {
     
$vars['brandbar'] = _phptemplate_callback('brandbar', array('node' => agaric_node_load_view($vars['node']->nid)));
    }
// ...
?>

This seems quite an inefficient way to do this though. Probably we could call on CCK to render values per-field? It would be nice, also, if Drupal were caching the view node information, and if it were accessible without our using this whole retreaded function.

 

Post new comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <small> <pre> <strike> <sub> <sup> <kbd> <s>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.