Twig forgets array-keys

前端 未结 3 871
无人共我
无人共我 2020-12-31 18:23

I have a weird problem with twig in Symfony2. I am using the following array:

[days] => Array
    (
        [1] => Array
            (
                         


        
相关标签:
3条回答
  • 2020-12-31 18:47

    also you can try this :

    {% for key,value in users %}
        {{ key }}
    {% endfor %}
    

    or maybe look into the "loop" object defined in the for loop

    http://twig.sensiolabs.org/doc/tags/for.html

    0 讨论(0)
  • 2020-12-31 18:49

    Maybe this

    http://www.twig-project.org/doc/templates.html

    By default, a loop iterates over the values of the sequence. You can iterate on keys by using the keys filter:

    <h1>Members</h1>
    <ul>
      {% for key in users|keys %}
        <li>{{ key }}</li>
      {% endfor %}
    </ul>
    
    0 讨论(0)
  • 2020-12-31 18:58

    It's not related on twig, it's a known gap in doctrine-mongodb using embeddedDocuments. Doctrine can't handle key-Values from embeddedDocuments, it will reorder the keys beginning from 0 and will so ignore the right key-values. Thank you anyway for your help :).

    0 讨论(0)
提交回复
热议问题