"Unexpected tag name" syntax error in Symfony2/Twig

Asked

Viewed 82 times

4

My list has the code below:

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

but when running, I get the following error message:

Unexpected tag name "post" (expecting closing tag for the "for" tag defined near line 3) in /home/Jose/Downloads/projects/Symfony/src/Learnsf/Bundle/Blogbundle/Resources/views/Post/list.html.Twig at line 5

How to fix?

    • posts is an array that comes from the controller. * post is the page variable that should be displayed in the loop, and is not declared on the page.
  • check that the posts variable is not empty, with no content.

  • in symfony profiler > Doctrine, expanding queries, shows a line as a result (exactly the number of records I have in the database). Some other alternative?

1 answer

2


Try it this way

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

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

  • Thanks Fabio. It worked right here. the problem really was marking display, it has to be {{}}.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.