2

Hey guys I tried to render a field on to the page template and it works fine on all pages except login/registration/profile pages.

Here's the code:

    <h3> 
     <?php print render(field_view_field('node', $node, 'field_introduction', array('label'=>'hidden'))); ?>
    </h3>

Here's the error: enter image description here

  • How is $node getting assigned ? Can you display full code.. ? Check your Drupal Log Messages or apache php error log.. – Anil Sagar May 1 '14 at 16:52
  • Not sure, i'm pretty much a novice and found the render code on this page drupal.org/node/950434 and then just pasted it in :/ – SlightlyClever May 1 '14 at 16:55
0

You need to load the node to render it if the page you are viewing is other than node page... In node page page.tpl.php contains $node object.. See page.tpl.php documentation for more details...

$node: The node object, if there is an automatically-loaded node associated with the page, and the node ID is the second argument in the page's path (e.g. node/12345 and node/12345/revisions, but not comment/reply/12345).

If other than node page you need to load the specific node from which you want to render the field in your login/registration/profile pages.. You can override page.tpl.php for specific pages.. For more details see Template suggestions..

To load the node specifically you can use node_load API function...

$node = node_load($nid); // Where $nid is node id
  • 1
    The thing is, that field (field_introduction) is only available in the 'Basic Page' content type. So i've just written a conditional statement to only display the field for that node type: – SlightlyClever May 1 '14 at 17:07
  • <?php if (isset($node)) { if ($node->type == 'page') { print '<h3>'; print render(field_view_field('node', $node, 'field_introduction', array('label'=>'hidden'))); print '</h3>'; } } ?> – SlightlyClever May 1 '14 at 17:08
  • Awesome.. If one of the answers above fixes your issue, you should accept it (click the check mark next to the appropriate answer). That does two things. It lets everyone know your issue has been resolved, and it gives the person that helps you credit for the assist. See here for a full explanation – Anil Sagar May 1 '14 at 17:12

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.