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 选项


基础教程推荐
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01