1

I hove a content type that editors can 'attach' related nodes to.

When I 'theme' / 'style' nodes of this content type through view mode everything is basically fine: the related nodes are rendered as teasers and I can style them as I like.

Now I need to wrap the list of related nodes in an extra class e.g. 'related-nodes' according to the output of another field. For example the editor chooses 'round corners' from a list field, then the css class "rounded" should be added to the wrapper of the list of related nodes should.

I am aware I can remove the entity reference field from the display settings and preprocess it through template.php. But then how do I preprocess the list in template.php? So far I just don't know how to actually access / handle it.

In devel tab I do get the array of related items. I could of course loop through that array and re-build node by node thruogh node_load – but since I only want to wrap that loop re-rendering each node feels wrong. Any suggestions?

3
  • Fences may be able to help with that
    – Clive
    Commented May 7, 2015 at 11:43
  • Thank you! But I actually need to add classes according to conditions previously read from another field… Commented May 7, 2015 at 11:48
  • Ah ok - a quite straightforward option would be to implement hook_node_view() in a custom module and add a #prefix and #suffix to the field element (prefix of <div class="foo">, suffix of </div>)
    – Clive
    Commented May 7, 2015 at 11:49

1 Answer 1

0

As per @Clive comment, Fences module may be able to help with that.

A quite straightforward option would be to implement hook_node_view() in a custom module and add a #prefix and #suffix to the field element (prefix of <div class="foo">, suffix of </div>)

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.