1

I am overriding a Display Suite view mode of a node using the template suggestion myLayout-node-myNode-full.tpl.php.

I am getting the $node->content using the node_build_content function. Then I have access and I am rendering all the node display fields using:

drupal_render($node->content['field_myField'])

But I cannot render fieldgroups using the drupal_render function, as it requires array parameter, but my fieldgroups are stdClass objects that can be accessed as:

$node->content['#groups']['group_myGroup']

Printing the $node variable, I do not get any other reference to fieldgroups, eg. $node->content['group_myGroup'] does not exist.

Any suggestions on how I could render fieldgroups in my template file in Drupal 7?

1

node_build_content is probably not suitable for your use case. However you should use node_view instead which calls node_build_content anyway but returns you the actual renderable array after it processes it and sends it through an alter as well.

For example:

function mytheme_preprocess_node(&$vars) {
  if (!empty($vars['node'])) {
    $node = $vars['node'];

    if ($node->type == 'my_content_type') {
      $vars['content'] = node_view($node); //optionally supply view_mode as a second argument
    }
  }
}

Now you can just drupal_render($content) from your node template.

  • This worked perfectly, now I have the $content variable with the actual renderable array which contains fieldgroup arrays too. Thank you. – Maria Ioannidou May 27 '15 at 11:44
  • UPDATE: Actually I already had the $content variable provided in my DS template file, without the need to use the node_view function. – Maria Ioannidou May 28 '15 at 8:16
  • I thought so, I was wondering why you were rendering the content manually. Thought you were doing something with DS arrays. – Beebee May 28 '15 at 9:36

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.