Jay
Jay

Reputation: 336

Variables are being ignored using the Twig Include template tag

I have setup the following:

{% include '_elements/page-heading.html' with {'shortTitle': 'entry.shortTitle','title':'entry.title'} %}

However, when the page renders this template it is actually outputting "entry.shortTitle" in the page when it should surely actually know what the entry.title is for this page.

e.g. it should say "Latest News" not "entry.title".

Just wondering why this would be?

Thanks!

Upvotes: 1

Views: 194

Answers (1)

xabbuh
xabbuh

Reputation: 5881

Enclosing entry.shortTitle with (single) quotes tells Twig that this simply is a string. When you want to pass the value of a variable, you have to leave away the quotes:

{% include '_elements/page-heading.html' with { 'shortTitle': entry.shortTitle, 'title': entry.title } %}

Upvotes: 3

Related Questions