0

I would like to add something to my $content variable to add on my node template file, but where is this variable composed? I assume it's in the template.php file but what specific function composes the content of the $content variable?

4

If you are referring to the $content variable that is available in node.tpl.php, its value is set in template_preprocess_node() from the following code:

  // Helpful $content variable for templates.
  $variables += array('content' => array());
  foreach (element_children($variables['elements']) as $key) {
    $variables['content'][$key] = $variables['elements'][$key];
  }

$variables['content'] is then passed to field_attach_preprocess().

  // Make the field variables available with the appropriate language.
  field_attach_preprocess('node', $node, $variables['content'], $variables);

To alter the content of the $content variable, you can implement hook_preprocess_node() (in a theme, or a module), or hook_field_attach_preprocess_alter().

Remember that what in a template file is $content, in other places is $variables['content'].

| improve this answer | |
  • Great! Thanks for your help. The hook you gave me did the trick! – Michiel May 4 '12 at 14:06
0

In template.php write this function

function hook_preprocess_page(&$variables) { // $variables will contain that content variable }

of you can use

function hook_preprocess_node(&$variables) { // $variables will contain that content variable }

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.