aditya aditya - 1 year ago 225
Twig Question

How to use php json_encode options in twig file with json_encode twig function

I am trying to use twig json_encode function but when I do this

var packageDetails = {{(packageDetails|json_encode)}};

and packageDetails is an array of array passed from controller

It gives me error saying

invalid property id

because of

so I want to use escape filter;
how do I use it?

Answer Source

Is it simply because you are not wrapping your output in quotes?

var variable = '{{{reference}}}';


The actual answer to solve the question was adding |raw to the tag as per comments

var packageDetails =  {{(packageDetails|json_encode|raw)}};
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download