How to show a variable of node in page template I have created a content type with some fields in Drupal 7. It output in node.tpl.php of course. But I wonder if I want to display some fields somewhere within the page.tpl.php, how to go about it. e.g. output a content types' field in the header/footer in page.tpl.php or anywhere.
This question is more or less a duplicate of https://stackoverflow.com/questions/8074485/drupal-7-how-to-render-custom-field. But I'd rather see the answer and question here on Drupal.stackexchange.com.

This goes into your template.php or in a module included file.

function THEME_OR_MODULE_preprocess_page(&amp;$vars) {
  $vars['VAR_NAME'] = '';
  // Get the object and do some other checks based on what you need.
  if (($node = menu_get_object()) &amp;&amp; $node-&gt;type) {
    // Generate a render array for the node.
    $view = node_view($node);
    // "Create" a new variable for the page.tpl.php.
    // This will expose $VAR_NAME in the page template.
    // You will most likely have to clear your cache.
    $vars['VAR_NAME'] = drupal_render($view['FIELD_NAME']);
  }
}


And then in your page.tpl.php:

HTML
&lt;?php print $VAR_NAME; ?&gt;
HTML


You might also have to hide the field in your node template, if you don't want to print the field twice. Check at hide() for that.