User login

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

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

Searched words: 
drupal call template file from template.php

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • 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>
  • Lines and paragraphs break automatically.

More information about formatting options

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