Search code examples
phpsymfonytwigsilex

How to have twig path() with silex slug?


In silex I have something like

$controllers->get('/{id}', 'Controllers\\Login::index')->bind('login');

when in twig I try to get path('login') I get exception

("Some mandatory parameters are missing ("id") to generate a URL for route "login"."). ?

I know this is because of {id} and I have to pass a second parameter to path() but how should it look like?


Solution

  • In order to pass parameters to twig path, use the following syntax:

    {{ path('login', {'id': 'your-id-here'}) }}
    

    you can have a look at the documentation here:

    Path() function documentation, symfony

    You can pass several parameters as explained here:

    SO: several paremeters in twig