0

I have created a custom page--mycontent-type.page.tpl for customizing display with html tags classes & attributes.
I'am unable to call that content type fields & their label.
I've tried these to print values but not worked for me.

  1. <?php print render($content['field_name']); ?>
  2. <?php print render($page['content']['field_name']); ?>
  3. <?php print render($fields['field_introduction']->content); ?>

Please suggest me what code call the actual fields & label. Thanks in advance :)

5
  • 2
    page tpl's are quite high level and after all of the content has been pulled together for rendering. If you want to change things on a specific content type you might be better using node--mycontent-type.tpl.php. Or is there a specific reason you need the node fields in the page.tpl
    – Leigh
    Commented Jan 23, 2019 at 10:23
  • Yes I have some specific reason to call field's label & its value individually and add many classes attributes some javascript and extra headings that I'am unable to do by field formatter class module. Commented Jan 23, 2019 at 11:53
  • If you’re not preprocessing then it won’t matter what template you’re using. I don’t see how a page template changes this vs a node template. These variables don’t exist at the page level.
    – Kevin
    Commented Jan 23, 2019 at 12:33
  • The question wasn't very clear but the reason I suggested it would be in a page.tpl within $content you'd only have the regions. Within the node tpl you'd have the actual node fields within $content (plus $node) which looked to be what he was after
    – Leigh
    Commented Jan 23, 2019 at 12:38
  • Thanks, gentleman for your suggestions.....The reason being I am asking this question because my design is ready with html css javascript jquery.....the problem I am facing in customizing it to drupal 7 theme is that the Labels & values has lots of css classes & attributes & some inline javascript. So I am unable to put those classes javascript by content type manage display field formatter method. Please suggest me some solution for this Commented Jan 24, 2019 at 4:29

1 Answer 1

0

For the objective of adding classes to fields in a node (as you made clear in your comment) you can use hook_node_view to intercept the node and then you can change the markup of your fields. You can find detailed examples here.

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.