0

Node page is not loading once I add below code

 drupal_render($node_view);  

I was referring https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_view/7 and added below code in my node--type.tpl.php

<?php
  $node = node_load($nid);
  $node_view = node_view($node);
  $rendered_node = drupal_render($node_view);
  echo $rendered_node;
?>
5
  • are you sure $nid has value ?
    – Ziftman
    Commented Feb 4, 2016 at 6:27
  • yes.i declared $nid=$node->nid . If i hard code node id of type of itself the page is not loading, if i give node id of other types the page is loading.
    – rks
    Commented Feb 4, 2016 at 6:53
  • you want to get views data?
    – jsh
    Commented Feb 4, 2016 at 6:58
  • i want to print node content in a particular view mode
    – rks
    Commented Feb 4, 2016 at 7:01
  • Can you define "not working"? What happens? A white screen, a timeout, an error message? Is there something relevant in the Apache/PHP/Drupal logs? Commented Feb 4, 2016 at 8:09

1 Answer 1

1

As I don't have the Drupal sources at hand right now, I didn't digg into it yet. But I'm pretty sure the node_view() function is using your node--type.tpl.php for rendering its output.

So calling it within your template will lead to a recursion. You might want to check on that.

1
  • Good point. But it would only lead to recursion if the node loaded with node_load($nid) is of the same bundle as the "type" in node--type.tpl.php, right? Commented Feb 4, 2016 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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