title: Find on which item route from the menu I am
body: <p>I'm currently working on a Symfony 4.4 web application.</p>
  <p>The menu can be changed by the administrators of my app, so there is a table with these properties :</p>
  <p><a href="https://i.stack.imgur.com/kNJyq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kNJyq.png" alt="enter image description here" /></a></p>
  <p>Because I got routes with some parameters (eg: a slug or an id, and the slug can change so it's not a great identifier).</p>
  <p>The problem is that I want to know on which menu item I am, to keep the menu opened (to add an active class on &lt; li &gt; items) but I can't find a way to do it properly.</p>
  <p><strong>What I tried :</strong></p>
  <p>Identify the route with something like that :</p>
  <pre><code>&lt;li&gt;{% if app.request.get('_route') == 'foo_products_overview' and app.request.get('slug') in [&quot;entityslug&quot;] %} class=&quot;active&quot; {% endif %}&gt;&lt;/li&gt;
  </code></pre>
  <p>But parameters are not the same for each route of my app (mutliple entites using id or slug to find one).</p>
  <p>Here is the way my menu items are displayed :</p>
  <pre><code>{% if child2.getMenuItems()|length &gt; 0 %}
      &lt;ul class=&quot;collapse nav-sub&quot; aria-expanded=&quot;false&quot;&gt;
          {% for child3 in child2.getMenuItems() if child2.getMenuItems()|length &gt; 0 and child3.level == 4 and (is_granted(child3.roles) or child3.roles is empty) %}
              &lt;li class=&quot;{% if child3.getMenuItems()|length &gt; 0 %}nav-dropdown{% endif %}&quot;&gt;
                  &lt;a class=&quot;{% if child3.getMenuItems()|length &gt; 0 %}has-arrow{% endif %}&quot;
                      href=&quot;{% if child3.route is not null %}{% if child3.routeParameters %}{{ path(child3.route, {'id': child3.routeParameters}) }}{% else %}{{ path(child3.route) }}{% endif %}{% else %}#{% endif %}&quot;
                      aria-expanded=&quot;false&quot;&gt;
                      &lt;span&gt;{% if &quot;ROLE_ADMIN&quot; in child3.roles %}&lt;i class=&quot;la la-eye-slash text-danger mr-2&quot;&gt;&lt;/i&gt;{% endif %}{{ child3.name|raw }}&lt;/span&gt;
                 &lt;/a&gt;
             &lt;/li&gt;
          {% endfor %}
       &lt;/ul&gt;
    {% endif %}
  </code></pre>
  <p>Have you ever had this problem?</p>
  <p>Maybe there's a way with KnpMenu? (<a href="https://symfony.com/bundles/KnpMenuBundle/current/index.html" rel="nofollow noreferrer">https://symfony.com/bundles/KnpMenuBundle/current/index.html</a>) I'm not using it for the moment.</p>