Evanss
Evanss

Reputation: 23613

Include twig template with values for nested placeholder?

I have a link template:

link.twig:

<a class="something" href="{{ url }}">{{ text }}</a>

And im calling the template and passing it values:

page.twig:

{% include "link.twig" with {'url': 'www.google.com', 'text': 'Search engine} %}

This was working but now I need to have url and text as part of a link object:

<a class="something" href="{{ link.url }}">{{ link.text }}</a>

How can I pass values from page.twig? The following gives me a white screen of death:

{% include "link.twig" with {link.url: 'www.google.com', link.text: 'Search engine} %}

Upvotes: 1

Views: 428

Answers (1)

alexf
alexf

Reputation: 1301

You can directly include an array :

{% include "link.twig" with {link : { url: 'www.google.com', text: 'Search engine'} } %}

Upvotes: 1

Related Questions