1

I have following set of an array that is pass to twig file.

others ={
          0:{id : 10, name: krist},
          1:{id : 20,  name: ryan}
         }

When I retrieve back from twig file, I retrieve as follow.

{% for other in others %}
 {{other.id}}
{% endfor %}

The above method always shows the error as follow:

An exception has been thrown during the rendering of a template ("Notice: Array to string conversion").

How can I fix this issue?

5
  • That error occurs when you try to convert an array into a string check wheater you print your output is not an array if this then you have convert this into a string first. Commented Jan 3, 2018 at 4:44
  • how can i do it? Commented Jan 3, 2018 at 5:10
  • by debugging you variable you can check that it is an array or string. or you can share your complete code for more reference. Commented Jan 3, 2018 at 5:17
  • Try {{ dump(other) }}. Commented Jan 3, 2018 at 6:22
  • please you can share your complete twig file ? Commented Jan 3, 2018 at 23:10

1 Answer 1

2

You can try this.

{% for other in others %}
    {% for o in other %}
        {{o.id}}
    {% endfor %}
{% endfor %}

or

{% for other in others %}
    {{other[0].id}}
{% endfor %}
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.