0

I want to return a "global" variable from a field template file

Assume I have a content type called "basic_page". Basic Page has a field called "my_field". In the template for basic page (node--basic-page.tpl.php), I render "my_field" by calling:

$fieldMarkup = drupal_render($content['field_my_field']);

In field--field-my-field.tpl.php I do whatever I need to do to return the field HTML / markup - no problems here. But I want to return a variable to node--basic-page.tpl.php as well. Is there a way to insert this variable into the node render array, or something of the sort?

I do not want to do this in a hook_preprocess function. If there is no other option I will, but was hoping I can avoid this.

1 Answer 1

2

Use template_preprocess_field in your template.php and add your variable there.

Then in your tpl.php you can easily access that variable and render that variable along with your markup.

0

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.