0

I have a twig array i get from a hook, when i dump(array) the array it returns this array:

array:1 [
  0 => array:2 [
    "Key1" => "Value1"
    "Key2" => "Value2"
  ]
]

This is how i dump it:

<div> {{ dump(array) }} </div>

But when i try to print this it returns Nothing:

<div> {{ array }} </div>

I also am trying to convert it to a javascript array like this but it returns null:

var test = {{ itm|json_encode() }};
console.log(test);
Bleron Parduzi
  • 117
  • 1
  • 8
  • Please [update](https://stackoverflow.com/posts/63808906/edit) your existing question in order to provide more information/updates about the problem – DarkBee Sep 10 '20 at 08:17
  • It's not an exact duplicate. The linked answer "could" be used to convert from PHP to JS array syntax (or simply pass a pre-generated JS string into the template). But Twig also has filters, which might suit better, eg. `{{ data|json }}` or `{% set var = data|json %}`. – Martin Zeitler Sep 10 '20 at 08:36
  • Not sure why u'r saying, anyway if you print an array like that, the output will be [Array](https://twigfiddle.com/fkrjbs), not nothing. Make sure u enable debug so you can see any errors – DarkBee Sep 14 '20 at 12:13

0 Answers0