I have a Twig array and I want to send it to JavaScript:
<script>
var packages = {{packages}}
</script>
Error! Array to String Conversion.
How should I do that?
I have an array from twig named filters, this single line did the job
const filters = JSON.parse('{{ filters | json_encode | raw }}');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With