I have a multivalue entity reference field, referencing basic content. The content (node) view is controlled via display modes (display modes is probably not relevant to the question)
Right now the entity reference field template is 'boilerplate' and just outputs the content in a for loop.
{% for item in items %}
{{ item.content }}
{% endfor %}
My display node template, node--[content type]--[display mode].tpl.twig has custom markup, and granular output of field values.
However somewhere 'deep' in this template I need to alter the markup in accordance with the position this node has in the parent referencing entity.
i.e.
- entity reference field:
- node 1
- node 2
- node 3 <-- pass this list position value somehow into the child node template, so i can change the markup inside
- node 4
I've been stepping through preprocessor variables in node_preprocess and field_preprocess, but I'm not really clear if the child node is 'aware' of its parent field, or more importantly the hierarchy of the parent field, and its position in it.
Any help or pointers much appreciated!