0

I have a custom page template (Drupal 7) created from a basic page and I call it page--node-84.tpl.php. I'd like to manually print/render the 'body' field from this page and so I tried that doing this:

<?php print render($content['body']); ?>

But that is not working because I believe I can only print a field when using a node template and not a page. Correct?

Could someone help me with a pre-processing function to be able to print a field in a page template. Or maybe using a custom node template is the way to go?

1 Answer 1

0

The available variables differ between the page.tpl.php versus the node.tpl.php (see the top of each of those links for documentation of the default variables).

If the default variables in the templates don't meet your needs, you can customize them using preprocess functions. See the documentation for template_preprocess_page to get an idea of how the variables get added. NodeOne has a screencast on "Providing new template variables" that might also be helpful.

2
  • I've looked into the variables for the page template and have come to the conclusion that a preprocess function is needed. I don't know much PHP so that is where I was hoping for a bit of help. Thanks anyway.
    – Dan
    Apr 16, 2013 at 23:00
  • @Dan, please see the updated answer. I've added a couple more links to details on adding variables via preprocess functions.
    – Matt V.
    Apr 16, 2013 at 23:11

Your Answer

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

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