User login

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

Searched words: 
drupal call template file from template.php

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.

Resolution

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Internal paths in single or double quotes, written as "internal:node/99", for example, are replaced with the appropriate absolute URL or path. Paths to files in single or double quotes, written as "files:somefile.ext", for example, are replaced with the appropriate URL that can be used to download the file.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.