I created a new content type with several fields in it. How would I print out those fields anywhere on the page that I need them like in the sidebar and other areas? What is the syntax for printing out a field? Also, I think I have to name a PHP file after the content type. What do I name it in Drupal 7?
3 Answers
This is best accomplished with Render Arrays. Please read Theming Node Form into Regions for a tutorial.
I think the question is how to put fields from a node to the page itself. You have to use hook_page_alter() and you can do something like this:
$page['sidebar_first']['node_links']=$page['content']['system_main']['nodes'][$nid]['links'];
for putting node links in the sidebar.
For a field from a node you can do something like this:
$page['sidebar_first']['test_block']=$page['content']['system_main']['nodes'][$nid]['field_your_field'];
Note: $nid
si the desired nid from the $page['content']['system_main']['nodes']
array.
The idea is that you can modify anything that a region contains and you can easily create blocks in any region with this hook.
I think you should install the devel module and do a
dpm($node);
You'll be able to see all the data contained in the node and therefore, you'll be able to use them as you want.
-
I installed the Devel Module and put in <?php echo dpm($node); ?>– JordashCommented May 6, 2011 at 2:36
-