1

I have array in twig sent by php script.

You can access the each value as in html file like this below.

{% for a in myArray %}
{{a.date}}{{a.high}}
{% endfor %}

However Now I want to put the data in each object. How can I do this??

<script>
for (var i = 0; i < length; i++) {
        chartData[i] = ({
            date: newDate,//to use value from twig array!!
            high: high,
            low: low,
        });
</srcipt>

1 Answer 1

1

You can do it with Twig's json_encode filter ( It's using PHP's json_encode function )

<script>
    var chartData = {{ myArray|json_encode() }}
</script>
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.