Skip to main content
edited tags
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284
Source Link

Return a variable from field template

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.