Displaying a Drupal content type field outside of a node -
i have created custom field on content type in drupal 7 need display outside of node, in separate area on page.
similar how $title variable works (in can place in page.tpl.php file) able create variable called $subtitle call data current node , allow me print out variable in area on page.tpl.php file.
i've seen view examples seeming use views , blocks accomplish task, seems bit excessive , wondered if there easier way.
there easier way, need bear in mind though not every page node page, , not every node page of right content type should selective. add theme's template.php file:
function mytheme_preprocess_node(&$vars) { $node = $vars['node']; if ($node->type == 'my_type') { $vars['subtitle'] = $node->field_my_field[language_none][0]['value']; } }
then in page.tpl.php
should this:
if (isset($subtitle)) : echo $subtitle; endif;
make sure clear caches (at admin/config/development/performance) once you've implemented hook in template.php or drupal won't pick up.
Comments
Post a Comment