Search code examples
phpsymfonyurlencodesymfony5

Symfony automatically urlencodes routes


I am using twig to call a route

<a href="{{ path('organisation_feedback', {'id': org.id, 'slug': org.name}) }}">Feedback for organization</a>

I want this path to call my anchor on my organisation-detail page so it jumps right to it

<section id="feedback">
    <div class="row">
        <div class="col-md-6 col-sm-6 col-12">
        <h1>Feedback for organization</h1>

            {{ form (form_organizationFeedback)}} 
        </div>
    </div>
</section>

My route is defined like this

organisation_feedback:
    path: /organisation/{id}/{slug}#feedback
    controller: App\Controller\InsembelController::organisation_detail

Unfortunately what seems to be happening is that symfony routes automatically get urlencoded so the link I am getting in my browser looks like this:

http://symfony.localhost/organization/20/exampleorganization%23feedback

How can I stop symfony from encoding my route so it actually redirects to #feedback and not %23feedback


Solution

  • In twig fragment should work

    <a href="{{ path('organisation_feedback', {'id': org.id, 'slug': org.name, '_fragment' : 'feedback' }) }}">Feedback for organization</a>