Syntax error "Unexpected tag name" in Symfony2 / Twig

4

My list has the following code:

<h1>Posts</h1>
{% for posts in post %}
    <article>
        <h2>
            {% post.titulo %}
        </h2>
        <div class="content">
            {% post.conteudo %}
       </div>
    </article>
{% endfor %}

But when I run, I get the following error message:

  

Unexpected tag name "post" (expecting closing tag for the tag for near line 3) in / home / jose / Downloads / projects / Symfony / src / LearnSF / Bundle / BlogBundle / Resources / list.html.twig at line 5

How to fix?

    
asked by anonymous 04.09.2014 / 12:23

1 answer

2

Try as follows

<h1>Posts</h1>
{% for post in posts %}
    <article>
        <h2>
            {{ post.titulo }}
        </h2>
        <div class="content">
            {{ post.conteudo }}
       </div>
    </article>
{% endfor %}

The {% %} tag is for "do something" and the {{ }} tag is "show something". Your for is inverted, for correct is like this: {% for item in lista %}{% endfor %}

    
04.09.2014 / 15:00