0

Are node data (e.g. title, body, comments) stored somewhere in the renderable array $page, and converted into HTML during rendering? Or does a renderable array just contain properties that indirectly cause to load particular templates files?

Where are variables that store these values printed?

node

1
  • how i do that ?
    – GiLL
    Aug 31, 2012 at 12:32

3 Answers 3

1

Yes, it's probably in there somewhere. However, it much easier to get the current node object (if there is any) with the menu_get_object() function:

if ($node = menu_get_object()) {
  // Do stuff with $node.
}
3
  • i asked two situation, yes to what ?
    – GiLL
    Aug 31, 2012 at 13:51
  • 2
    You shouldn't ask two questions. That's not how the site works. Yes is the response to the answer in the question title. For the second one, install devel.module and use dpm($node), that will tell you what's in there.
    – Berdir
    Aug 31, 2012 at 15:38
  • sir, i am drupal newbie can you please elaborate this answer in simple words. please help me, rendering concept confuse me too much
    – GiLL
    Sep 1, 2012 at 6:41
1
+50

I can advice three places where you can alter node render array:

  1. hook_node_load . Called when node is just have been loaded from DB.
  2. hook_node_view . This hook is called after node load. (As for me this is the best place to alter node render array). You can find render array in $node->content.
  3. After this two hooks node render array goes to themming. You can alter node in your node template file(node.tpl.php). In node tpl file variables are printed using php print. E.g.

    print render($content);

4
  • milkovsky,you explain how i alter the node data before it go for theming. but my question is what happen when line<?php print render($page['content']);?> executed in page.tpl.php that make node.tpl.php comes into play? In above picture you see node title(defui et populus)come first,then body(commodo exerci..)who define serial order of these two field? Is in render array variable that store node title, stored just above node body variable, that why it comes first or it depend upon node.tpl.php file coding structure.milkovsky if you know rendering array and template concept please help me
    – GiLL
    Sep 15, 2012 at 15:25
  • Of course page title and page body are separated. The order of them you can define in the page.tpl.php file. Find title string "print $title;" and "print render($page['content']);" in your_theme_folder/page.tpl.php or in modules/system/page.ptl.php. You can see that title and content are printed in different places. Change order here OR as alternative you can use "Delta blocks" module to use page title as block.
    – milkovsky
    Sep 17, 2012 at 12:53
  • is it means node title is not part of render array $page['content']?
    – GiLL
    Sep 23, 2012 at 10:47
  • yes title is rendered by 'print $title' usually in <h1> tag
    – milkovsky
    Sep 26, 2012 at 8:41
0

yes, A render array is an associative array which conforms to the standards and data structures used in Drupal's theme rendering system. for more info check out: Render Arrays in Drupal 7

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.