为动态标签添加前缀

Adding prefix to a dynamic tag

我需要以下实施方面的帮助。我想为我的动态标签添加一个前缀,然后让 twig 获取这个标签的值。

{% set result = 'text.journey_service_'~ data.addServ.serviceName %}

{{ result }}

Actual output => text.journey_service_SMALL_PET

Expected output => {{ text.journey_service_SMALL_PET }} = > Dog

这看起来无效:

{% set result = 'text.journey_service_'~{{ data.addServ.serviceName }} %}

如果你想连接一个字符串和一个变量,你最好使用:

{% set result = 'text.journey_service_'~ data.addServ.serviceName %}

如果你想使用result作为变量名来打印一些东西,你可以使用下面的代码(如中给出的):

{{ attribute(_context, result) }}