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?
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>
)