Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Json object : Twig

I have passed a JSON object to my twig template in symfony2, then i have assigned the object to JavaScript variable.

My object is like

[{"data":"{"params":{"id":"1","width":"98","height":"101","x":"151","y" ....

Now when i alert the object it shows the above objectarray() which is OK, but when i alert object.data it shows nothing.

Thanks

like image 507
Shaun Avatar asked Feb 26 '26 12:02

Shaun


1 Answers

I don't know if you solved your problem.
I have the same trouble, but this worked for me

# your_template.html.twig
<script type="text/javascript">
{% autoescape false %}
    var your_variable = {{ var_from_controller }};
{% endautoescape %}
</script>
like image 145
Federico Hoerth Avatar answered Mar 02 '26 14:03

Federico Hoerth