0

I'm trying to use a charting library within a Craft template.

The chart expects an array of numbers that I'm building up from a table but I'm getting an array of strings instead.

{% set donutData = [] %}
{% for p in block.donutValues %}
    {% set donutData = donutData|merge([
        p.value
    ]) %}
{% endfor %}

and then if I do {{ donutData|json_encode }} I get an array of strings returned that my chart library can't interpret.

value is set to be a number field in the Craft table column so not sure why I'm getting a string returned.

1

So it seems that even although the Craft field is set to number it doesn't actually define a number.

I changed the field from a regular Craft table field to a Super Table field and my {{ donutData|json_encode }} corrects spits out an array of numbers.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.