DumbDevGirl42069
DumbDevGirl42069

Reputation: 959

Can I pass a dynamic value from craft CMS to another template as well as a string value?

Can I pass a dynamic value from craft CMS using twig to another template as well as a string value? Using the following gives me a syntax error

"Twig_Error_Syntax: A hash key must be followed by a colon (:). Unexpected token "punctuation" of value "," ("punctuation" expected with value ":") "

        {% set myEntry= craft.entries.slug('myEntry').first %}
        {% embed '_layouts/_hero' with {
            'extraClasses': "{{ myEntry.featuredBgPosition }} hero--medium",
            'heroImage': myEntry.featuredImage.first
        } %}

Other answers say to not use curly braces but this doesn't work either

'extraClasses': myEntry.featuredBgPosition "hero--medium",

and when using it within the quotations I get the string myEntry.featuredBgPosition as a class

'extraClasses': myEntry.featuredBgPosition "hero--medium",

Upvotes: 0

Views: 556

Answers (1)

emarref
emarref

Reputation: 1311

The answers that suggest removing the curly braces are correct, but you need to concatentate strings with variables.

        {% set myEntry= craft.entries.slug('myEntry').first %}
        {% embed '_layouts/_hero' with {
            'extraClasses': myEntry.featuredBgPosition ~ " hero--medium",
            'heroImage': myEntry.featuredImage.first
        } %}

Upvotes: 1

Related Questions