How to use php json_encode options in twig file with json_encode twig function(如何使用 json_encode twig 函数在 twig 文件中使用 php json_encode 选项)
问题描述
我正在尝试使用 twig json_encode 函数,但是当我这样做时
I am trying to use twig json_encode function but when I do this
var packageDetails = {{(packageDetails|json_encode)}};
packageDetails 是一个从控制器传递过来的数组
and packageDetails is an array of array passed from controller
它给了我错误提示
invalid property id
因为"所以我想使用转义过滤器;如何使用?
because of "
so I want to use escape filter;
how do I use it?
推荐答案
仅仅是因为你没有用引号包裹你的输出吗?
Is it simply because you are not wrapping your output in quotes?
var variable = '{{{reference}}}';
更新:
解决问题的实际答案是根据评论将 |raw 添加到标签中
The actual answer to solve the question was adding |raw to the tag as per comments
var packageDetails = {{(packageDetails|json_encode|raw)}};
这篇关于如何使用 json_encode twig 函数在 twig 文件中使用 php json_encode 选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 json_encode twig 函数在 twig 文件中使用 php json_encode 选项
基础教程推荐
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- php中的foreach复选框POST 2021-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- php中的PDF导出 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
