1

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?

1 Answer 1

3
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,  ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.