-->

How to have twig path() with silex slug?

2019-08-26 17:43发布

问题:

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?

回答1:

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