0
votes

I have a HomeBundle in which I have Default controller that has 2 actions : one to render index.html.twig and another one to render part of the navbar. In my views, I have the default layout that the rest of the views extends.
I want to match the route of the second action in the Default controller to render its content to any route.
This is the action in DefaultController, I thought name="/" would match all routes.

    /**
 * @Route("/", name="navbar_boutique")
 */
public function afficherBoutiqueProductAction()
{
    $em= $this->getDoctrine()->getManager();
    $boutiques=$em->getRepository(Boutique::class)->findAll();
    return $this->render('@Souk/Default/boutique_navbar.html.twig', array(
        "boutiques"=>$boutiques
    ));
}

And this is boutique_navbar.html.twig:

{%extends '@Souk/layout.html.twig'%}
{%block boutique %}
<ul class="list-links">
    <li>
        <h3 class="list-links-title">Liste des Boutiques</h3></li>
    {% for b in boutiques %}
        <li><a href="{{ path('afficher_produit_boutique',{'idboutique':b.id}) }}"> {{ b.nom }} </a></li>
    {% endfor %}
</ul>
{% endblock boutique %}

As for layout.html.twig it contains the base template and I just want to display an element in its navbar. (it's the list of shops)

What am I doing wrong?

ps: When I add @Route="/test" for example, it works but only for /test and I want it to be for all routes.

1
No it's not. I'm using annotions and I'm not looking for error handling, it's just an element in the list of the navbar that has to be populated from an action in the DefaultController (I'm just getting all shops and displaying their names in the navbar)hadh

1 Answers

1
votes

Perhaps this solutions might be what you are looking for (with little editing): Symfony routing: match anything after first node

In your case, you would use wildcard annotation like this:

/**
 * @Route("/{anything}", name="wildcard", defaults={"anything" = null}, requirements={"anything"=".+"})
 */