Twig 细枝:在字符串中连接变量
我刚刚开始学习细枝,我真的被这个愚蠢的小问题困住了。连接这似乎不起作用eigenKleurInput最终将成为一个值:Twig 细枝:在字符串中连接变量,twig,Twig,我刚刚开始学习细枝,我真的被这个愚蠢的小问题困住了。连接这似乎不起作用eigenKleurInput最终将成为一个值: {% set eigenKleurInput = "acefbf" %} {% set customBackgroundColorInline = 'style=background-color: #' ~ eigenKleurInput %} 输出变量customBackgroundColorInline放在一个div中: <section {{ customBack
{% set eigenKleurInput = "acefbf" %}
{% set customBackgroundColorInline = 'style=background-color: #' ~ eigenKleurInput %}
输出变量customBackgroundColorInline放在一个div中:
<section {{ customBackgroundColorInline }}>
期望的产出将是
<section style="background-color: #xxx">
多谢各位 如果我正确理解了您的问题,那么问题是关于编码字符的:如果您在代码中添加了“细枝渲染为” 在这种情况下,应按如下方式使用:
{% set eigenKleurInput = "acefbf" %}
{% set customBackgroundColorInline = 'style="background-color: #' ~ eigenKleurInput ~ '"' %}
<section {{ customBackgroundColorInline|raw }}>
因此,输出将是:
<section style="background-color: #acefbf">
你可以在网上试试
希望这有帮助