0

When I dump an array in twig, it gives the following result:

 array(1) {
  [0]=>
  object(TEST\Bundle\BlogBundle\Entity\Follow)#364 (3) {
    ["id":"TEST\Bundle\BlogBundle\Entity\Follow":private]=>
    int(1)
    ["follower"]=>
    int(2)
    ["followed"]=>
    int(1)
  }
}

 int(1)

 int(1)

How can I access the follower parameter inside my loop which is:

{% for fol in followers %}

    <pre> {{ dump(fol)  }} </pre>

{% endfor %}

Thank you for your help.

1 Answer 1

1

Use TWIG attribute docs. Example:

{% for fol in followers %}
    <pre> {{ dump(attribute(fol[0], follower)) }} </pre>
{% endfor %}

Please make you sure that you have getters for follower in TEST\Bundle\BlogBundle\Entity\Follow or follower attribute is public.

Or simillarly print value:

{% for fol in followers %}
    <pre> {{ fol[0].follower }} </pre>
{% endfor %}
Sign up to request clarification or add additional context in comments.

7 Comments

Thank you for your time, but it is still not working, it gives me Variable "follower" does not exist in TESTBlogBundle:Dashboard:Followers.html.twig at line 10. I am new with twig
@whitelettersandblankspaces please provide result of your code. I mean result of <pre> {{ dump(fol) }} </pre>.
The result is in my question, first paragraph
Thank you very much. I have getter in my Follow entity, and I have follower as public attribute, but the problem is not resolved, even it is very logical what you are saying.
Error occurs because you have little mess in your array followers. First element of this array (index 0) is object, but second and third (indexes 1 and 2) are integer.
|

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.