嫩枝 - 使用引号作为分隔符连接过滤器(Twig - use quotation mark as s

2019-07-30 12:37发布

我通过我的模板字符串数组,我想转换为jaavascript数组:

控制文件(PHP):

$myVar = array('a','b','c');

所需的HTML:

var myVar = ["a","b","c"];

我尝试下面的代码(树枝):

var myVar = ["{{ myVar | join('","') }}"];

但树枝发生器引号转换为HTML实体,这是结果:

var myVar = ["a","b","c"];

一些想法?

Answer 1:

您需要应用的raw过滤器:

var myVar = ["{{ myVar | join('","') | raw }}"];


文章来源: Twig - use quotation mark as separator for join filter