I'm trying to pass a twig array variable to javascript, but for some reason it keeps stating that the variable does not exist.
My twig:
{% set clients = [] %}
{% for work in works %}
{% set clients = clients|merge([ work.name ]) %}
{% endfor %}
{% set client_array = clients|json_encode|raw %}
When I try and call client array with {{client_array}} I have no trouble whatsoever, it returns the correct array.
However my problem is when I try to define a javascript variable below in a javascript block on the page to be equal to client_array.
<script>
var clients = '{{ client_array }}';
...
</script>
I keep getting
Variable "client_array" does not exist.
I feel there's some dumb syntax error I'm making here. Can anyone see the problem?
{% block %}blocks in that template (or is it a different template)? if so, then it's possibly a scope issue. also: the quotes are probably a problem, if the var is json encoded, but not related to the twig error.