twigsymfony5

Title: Twig template error - Missing closing tag for loop


#[Route('/instructeur/lessen')]
class LessenController extends AbstractController
{
    #[Route('/', name: 'app_lessen_index', methods: ['GET'])]
    public function index(LessenRepository $lessenRepository){
        $vandaag = new \DateTime() ;
        $lessen = $lessenRepository->findBy(["datum" => $vandaag ]);
        return $this->render('/instructeur/lessen/index.html.twig', [
            'lessen' => $lessen
        ]);
    }
{% for lessen in lessen %}
    <tr>
        <td>{{ lessen.id }}</td>
        <td>{{ lessen.status }}</td>
        <td>{{ lessen.ophaalLocatie }}</td>
        <td>{{ lessen.lesdoel }}</td>
        <td>{{ lessen.naamLeerling }}</td>
        <td>{{ lessen.naamInstructeur }}</td>
        <td>{{ lessen.datum ? lessen.datum|date('Y-m-d') : '' }}</td>
        <td>{{ lessen.prijs }}</td>
        <td>
            <a href="{{ path('app_lessen_show', {'id': lessen.id}) }}">show</a>
            <a href="{{ path('app_lessen_edit', {'id': lessen.id}) }}">edit</a>
        </td>
    </tr>
{% else %}
    <p>No lessons found.</p>

I'm encountering an issue with a Twig template where I seem to be missing a closing tag for a loop. I've been trying to debug it, but I can't seem to find the exact problem.

Do you know how to fix it?


Solution

  • Hi there new developer the issue you are encountering with the temlpate misses indeed a for loop for lessen. you can try this?

    Please update me for if it works

    #[Route('/instructeur/lessen')]
    class LessenController extends AbstractController
    {
        #[Route('/', name: 'app_lessen_index', methods: ['GET'])]
        public function index(LessenRepository $lessenRepository){
            $vandaag = new \DateTime() ;
            $lessen = $lessenRepository->findBy(["datum" => $vandaag ]);
            return $this->render('/instructeur/lessen/index.html.twig', [
                'lessen' => $lessen
            ]);
        }
    TWIG:   {% for lessen in lessen %}
                <tr>
                    <td>{{ lessen.id }}</td>
                    <td>{{ lessen.status }}</td>
                    <td>{{ lessen.ophaalLocatie }}</td>
                    <td>{{ lessen.lesdoel }}</td>
                    <td>{{ lessen.naamLeerling }}</td>
                    <td>{{ lessen.naamInstructeur }}</td>
                    <td>{{ lessen.datum ? lessen.datum|date('Y-m-d') : '' }}</td>
                    <td>{{ lessen.prijs }}</td>
                    <td>
                        <a href="{{ path('app_lessen_show', {'id': lessen.id}) }}">show</a>
                        <a href="{{ path('app_lessen_edit', {'id': lessen.id}) }}">edit</a>
                    </td>
                </tr>
            {% else %}