Add more than one parameter in Twig path

SymfonyTwig

Symfony Problem Overview


How to add more than one parameter in Twig path?
Say you have this route :

article_show:
    pattern:  /article/{slug}
    defaults: { _controller: AcmeArticleBundle:Article:show }

You can do this in your twig template :

{{ path('article_show', { 'slug': article.slug }) }}

but what if you have this in your routing file:

_files_manage:
    pattern: /files/management/project={idproject}&user={iduser}
    defaults: { _controller: AcmeTestBundle:File:manage }

It looks like they didn't cover this in their documentation.

Symfony Solutions


Solution 1 - Symfony

You can pass as many arguments as you want, separating them by commas:

{{ path('_files_manage', {project: project.id, user: user.id}) }}

Solution 2 - Symfony

Consider making your route:

_files_manage:
    pattern: /files/management/{project}/{user}
    defaults: { _controller: AcmeTestBundle:File:manage }

since they are required fields. It will make your url's prettier, and be a bit easier to manage.

Your Controller would then look like

 public function projectAction($project, $user)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWissemView Question on Stackoverflow
Solution 1 - SymfonyElnur AbdurrakhimovView Answer on Stackoverflow
Solution 2 - SymfonyTac TaceloskyView Answer on Stackoverflow