1

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?

1
  • I guess the question is about the name to use for template files.
    – avpaderno
    Commented May 3, 2011 at 20:08

3 Answers 3

2

This is best accomplished with Render Arrays. Please read Theming Node Form into Regions for a tutorial.

1

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.

0

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.

2
  • I installed the Devel Module and put in <?php echo dpm($node); ?>
    – Jordash
    Commented May 6, 2011 at 2:36
  • And nothing happened.. Any ideas?
    – Jordash
    Commented May 6, 2011 at 2:36

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.