Home > Back-end >  How to echo a variable in Literals
How to echo a variable in Literals

Time:10-11

is there a way in twig to echo a variable in literals, like this?

{{ mb.get_the_post_thumbnail( post.ID, 'full', {'class': 'sec-mitarbeiter-image {{objectPositionClass}} '} ) }}

Result:

class="sec-mitarbeiter-image {{objectPositionClass}}"

Expected:

class="sec-mitarbeiter-image object-position-top"

CodePudding user response:

I guess you want simple string concatenation:

{{ mb.get_the_post_thumbnail(post.ID, 'full', {
    'class': 'sec-mitarbeiter-image ' ~ objectPositionClass
}) }}

Or interpolation:

{{ mb.get_the_post_thumbnail(post.ID, 'full', {
    'class': "sec-mitarbeiter-image #{objectPositionClass}"
}) }}

CodePudding user response:

Try this

{{ mb.get_the_post_thumbnail( post.ID, 'full', {'class': `sec-mitarbeiter-image $objectPositionClass `} ) }}

CodePudding user response:

try this. I think you miss to use $ with variable name. and {{ work similar like <?php so no need to use it again.

{{ mb.get_the_post_thumbnail( post.ID, 'full', {'class': 'sec-mitarbeiter-image $objectPositionClass '} ) }}
  • Related