如何在文字中回显变量

How to echo a variable in Literals

twig 中是否有一种方法可以像这样以文字形式回显变量?

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

结果:

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

预计

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

试试这个

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

我猜你想要简单的字符串 concatenation:

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

interpolation:

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