0

I'm starting to dig deeper into themeing and I'm thinking maybe I'm misunderstanding something.

Basically I want to break apart the way the content is laid out in my node--example.tlp.php file.

I've started doing that with some simple render statements like print render($content['group_factory_images']);

I started running into trouble when I wanted to pull the label off of the normally rendered flow and place them somewhere else with something like print render($content['group_factory_images']['label');

This wasn't working so I started to try and pull other items in, to see if it was a syntax issue or something else.

I came away with 2 questions: What is the right syntax to get labels rendered in a node?

And then; Can you only render a piece on content once? For example could I do something like rendering the body twice in the same node? (not that I would want to, but it illustrates the point I think:

print render($content['body']);

// other items rendered

print render($content['body']);

1 Answer 1

0

The display of a label is handled by the Field and not the template. The HTML for the field is passed to the template layer from the field API and the label HTML is lumped in with the field information itself. So basically you cannot alter or move the printing of the label in the template layer of theming. Consider the field data and the field label as one item in templating (i.e. $content['field_name'] contains the field data and label as one. Altering the label display (display label or not, inline, etc.) is done in the field display settings for the content type. The only way to alter the label is to do so at the field display level and again it is passed to the template with the field data as a final product.

Rendering content more than once, yes it can be done.

4
  • So I cannot hide the flield label in the content type "Manage Display" settings and then do something in the tpl file to show that label where I want to? Commented Aug 26, 2015 at 14:15
  • @ErikHanson You are correct.
    – Brady
    Commented Aug 26, 2015 at 14:24
  • I never would have guessed that, I've always assumed you could pull almost anything forward. Thanks for your help. Commented Aug 26, 2015 at 20:12
  • Yeah it's a pain. I recently ran into this trying to add a "help" icon next to the a field title on the add-to-cart form with Drupal Commerce. I had to give up till the new DC came out where I could write hooks to tear apart the add-to-cart form. There was no way of modifying it because it came as a field object.
    – Brady
    Commented Aug 27, 2015 at 4:34

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.