jquery - Map a php array to javascript -
jquery - Map a php array to javascript -
i have array in php:
<?php homecoming array( 'r' => '16:9', 'check' => array( array('w' => 640, 'q' => 70), array('w' => 960, 'q' => 70) ), 'window_height' => 800 ); i need in javascript, have:
<script>var config = "{{ json_encode(config::get('conf')) }}";</script> but im having problem getting each element out.
note: {{}} laravel echo.
assuming there no additional html escaping applied template engine, have remove quotes. json-encoding takes care of you.
<script>var config = {{ json_encode(config::get('conf')) }};</script> you can debug viewing raw output of php script. (usually "view source" in browser.)
now, don't know twig, according documentation there may improve way using own js escaping. untested obviously, give try:
{% autoescape 'js' %} <script>var config = {{ config::get('conf') }};</script> {% endautoescape %} javascript jquery
Comments
Post a Comment