将变量与字符串连接并将其设置在新变量中

Wal*_*rus 5 templates jinja2

例如,我试图设置一个变量,cmd = "echo 25"但它不起作用

{% set cmd = "echo {{ id }}" %}
Run Code Online (Sandbox Code Playgroud)

请帮忙修复它。

Van*_*mos 1

尝试这个:

{% set testing = 'it worked' %}
{% set another = testing %}
{{ another }}
Run Code Online (Sandbox Code Playgroud)

结果:

it worked
Run Code Online (Sandbox Code Playgroud)