How to pass parameters to route in Twig?

drmonkeyninja - 2 weeks ago

I'm trying to pass parameters to a route in Twig.

In blade I would use:-

{{ route('clients.mail', [$client->id, $month]) }}

How do I do this in Twig? I've tried using:-

{{ client.route('mail', [month]) }}

This fails. The route I have defined in my service provider is:-

'clients/{id}/mail/{month}' => [
    'verb' => 'get',
    'as' => 'default.module.support::clients.mail',
    'uses' => 'Default\SupportModule\Http\Controller\[email protected]'
],

month is a parameter that is being passed into the view based on a filter the page uses.

Answer

ryanthompson - 2 weeks ago

I think url_route($route, $parameters) is what you're looking for. url_* maps methods to Laravel's URLGenerator.

ryanthompson - 2 weeks ago

I think url_route($route, $parameters) is what you're looking for. url_* maps methods to Laravel's URLGenerator.

ryanthompson - 2 weeks ago

You might also want to look into entry routers: https://pyrocms.com/documentation/streams-platform/latest#models/entry-routers

drmonkeyninja - 2 weeks ago

Thanks Ryan, that does the trick. I'd tried just about everything but that.

{{ url_route('default.module.support::clients.mail', [client.id, month]) }}

ryanthompson - 2 weeks ago

Now you know ^_^

Keep in mind all those similar functions are available. session_*, str_*, as well as route_* and some others: https://pyrocms.com/documentation/streams-plugin/latest