slimphp / PHP-View

A Simple PHP Renderer for Slim 3 & 4 (or any other PSR-7 project)
MIT License
264 stars 60 forks source link

Inserting a path to a named route in a php-view template? #31

Closed pietmarcus closed 8 years ago

pietmarcus commented 8 years ago

As far as I can tell, there is no (clean) way to insert a path to a named route, or am I missing something? I have create a workaround which I am happy to contribute, but since I only started using the Slim Framework yesterday I want to make sure I am not missing something.

geggleto commented 8 years ago

I am not entirely sure what you mean when you said,

there is no (clean) way to insert a path to a named route

Could you clarify this?

Are you speaking about inserting the router so you can resolve a URL in your template via a named route?

geggleto commented 8 years ago

If this is the case, you can inject it into the renderer after you construct it.

https://github.com/slimphp/PHP-View/blob/master/src/PhpRenderer.php#L99-L101

$render->addAttribute('router', $router);

then in your template, $router->path_for();

pietmarcus commented 8 years ago

I have added the addAttribute line to the dependencies.php-file and everything works as desired. Thanks for the tip!