0

In drupal 7, I defined a field for a custom content type and am trying to display its value via page.tpl.php. Nothing is appearing in the rendered page.

Here's the relevant piece of page.tpl.php. The field is 'field_mast". Note that I added print $title just so I could be sure that this template is being used. It is.

    <h1>Perinote&trade; <?php print $content['field_mast'] ?><br>
       <?php print $title ?> <br>Organize Your Way</h1>

My content type fields are:

Label  machine name field type            widget
Title  title        Node module element
mast   field_mast   Text                  Text field
Body   body         Long text and summary Text area with a summary

And for Manage Display, I have:

Field   Label        Format
Body    <Hidden>     Default
mast    Above        Default

Finally, for my actual content, I have:

Title: Notes contacts....
mast: User Guide
Body <p>This user guide...
Text format: Full HTML

Any ideas on what I need to do to get 'mast' to print?

1 Answer 1

0

try

<h1>Perinote&trade; <?php print render($content['field_mast']); ?><br>

or this one

<h1>Perinote&trade; <?php print render($content['field_mast']->value); ?><br>

I recommend you to download and install devel module and write

<?php kpr ($content);?>

to see what $content contains. you can also call this function in hook_preprocess_page as well.

10
  • Hi. I installed devel but I'm not sure if I've done it right. After installation, "modules" showed three "development" modules. I enabled "Devel". Then, in "blocks", I saw "development" listed twice. Not sure if that comes from Devel. I placed both in the footer region of my page. Now, when viewing a page, I see list of menu items. Among them is "field info". If I click on that, I get a popup of Fields, Instances, ... I can see "field_mast" in the list. Not sure what to look for at this point. Commented Mar 27, 2015 at 17:53
  • I added kpr ($content) and it shows field_mast to have value NULL. Not sure why. It's defined for the page, as I show in my original post. Commented Mar 27, 2015 at 18:19
  • now write kpr($page['content'])
    – M a m a D
    Commented Mar 27, 2015 at 19:48
  • also in template.php and in hook_preprocess_node(&$variables) write kpr($fields) to see if the field has value
    – M a m a D
    Commented Mar 27, 2015 at 19:56
  • thanks again for your suggestions. I added kpr($page['content']) and got some output but I don't really know what to look for in the output. I also added kpr($fields) but that didn't even produce an empty rectangle. I experimented with hook_preprocess_node and hook_preprocess_page as well but am not sure which module to put it in. I tried templates.php and got "already defined errors". Any more ideas? Thanks. Commented Mar 27, 2015 at 21:02

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.