Twig - 使用引号作为连接过滤器的分隔符 [英] Twig - use quotation mark as separator for join filter
本文介绍了Twig - 使用引号作为连接过滤器的分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我向我的模板传递了一个字符串数组,我想将其转换为 jaavascript 数组:
I pass my template an array of strings which I would like to convert to a jaavascript array:
控制器文件(php):
Controller file (php):
$myVar = array('a','b','c');
所需的 html:
var myVar = ["a","b","c"];
我尝试以下代码(树枝):
I try the following code (twig):
var myVar = ["{{ myVar | join('","') }}"];
但是树枝生成器将引号转换为 html 实体,结果如下:
But the twig generator converts the quotation marks to html entities and this is the result:
var myVar = ["a","b","c"];
有什么想法吗?
推荐答案
您需要申请 raw
过滤器:
You need to apply the raw
filter:
var myVar = ["{{ myVar | join('","') | raw }}"];
这篇关于Twig - 使用引号作为连接过滤器的分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文