Reputation: 880
In my template Twig i hope to use a loop for into javascript,so i tried this but it doesn't work :
series: [{
name: 'Population',
data: [{% for SoResult in SoResults %} SoResult.pollanswerPoints {% endfor %}],
dataLabels: {
enabled: true,
and i have this error:
missing ) after argument list
[Stopper sur une erreur]
SoResult.pollanswerPoints
And i would like to have something like that :
data : [44,58,69]
Any Idea?
Upvotes: 1
Views: 1421
Reputation: 12717
series: [{
name: 'Population',
data: [
{% for SoResult in SoResults %}
{# write a comma to separate elements unless it is first one... #}
{% if loop.index0 != 0 %},{% endif %}
{# it's important to write quotes if elements are string in Javascript #}
"{{SoResult.pollanswerPoints}}"
{% endfor %}
],
dataLabels: {
enabled: true, ...
Upvotes: 3