Score:0

How do I pass a variable to a template file?

in flag

I have a template that defines a module that builds a paragraph.

This paragraph uses a field reference to link another type of content.

In my main paragraph I call this reference content with

{{ content.field_hero_slider_item_reference }} to display it.

This works, but I would like to be able to pass variables to it so that I can style the individual elements inside the reference with attributes from another field, say "settings".

I tried:

{% include with {'items': content.field_hero_slider_item_reference, 'attrs': attrs} %}

Unfortunately, there's something that breaks the display mechanism of {{ }}, albeit if I call dsm or kint on any of these variables (attrs or items) I can see exactly what I would need.

Any help or suggestion is appreciated

mradcliffe avatar
cn flag
I'm not sure if this has enough focus or details, but reference property is handled by the configured field formatter on that entity view display.
Kevin avatar
in flag
^ this. Any other peripheral variables would be in a preprocess hook.
Jaypan avatar
de flag
You can dump a variable in twig with `{{ dump(variable) }}`
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.