0

For custom content type page I used this:

function MYTHEME_preprocess_page(&$vars, $hook) {
    if (isset($vars['node'])) {
      // If the node type is "blog_madness" the template suggestion will be "page--blog-madness.tpl.php".
      $vars['theme_hook_suggestions'][] = 'page__'. $vars['node']->type;
    }
}

So now it means I can use page.tpl.php for my custom content type pages. So for the default Basic Page the template page is page--page.tpl.php and I did test it and it works. Except this:

I am trying to render some field outside . So I used this: <?php print render($content['field_banner']); ?> right outside <div id="content" class="column" role="main"> but it's not printing.

I was told this has something to do with node_load. But I'm not experienced with that.

  • Welcome! It would be helpful if you would update your post with a brief explanation of what your purpose is. Doing so not only helps people understand your question, they can also suggest alternative methods if a better way exists. Cheers - – othermachines Aug 27 '15 at 20:00
0

You will need to load the node object to get the field value, something like this:

$node = node_load($nid);
$field = field_get_items('node', $node, 'field_name');
$output = field_view_value('node', $node, 'field_name', $field[$delta]);
|improve this answer|||||
  • The loaded node is typically available in the $variables array passed to template_preprocess_page() when you are on a node view page. – mpdonadio Aug 27 '15 at 15:59
  • Wait, so where do I put this? – user3108268 Aug 27 '15 at 16:05
  • @MPD, I was under the impression definition that not a node page. and yes` template_preprocess_page()` or hook_preprocess_page() will have the node variables so no need to load the node. – sam2de Aug 27 '15 at 16:15
  • Please take a look at @MPD comments before, if this is a node page you should get the value in the variables array. I will update my answer in a bit. – sam2de Aug 27 '15 at 16:17
0

You can load node again in other place and render it fully or partially. Via block or something else. Node load is hard operation, use module entitycache to load the same nodes faster.

|improve this answer|||||
  • But I need only one field. – user3108268 Aug 27 '15 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.