Michelle Michelle - 1 month ago 9
Twig Question

Slim Framework, get route link in TWIG?

I definied my route so:

$app->get('/about', function ($request, $response, $args) {
return $this->view->render($response, 'about.twig');
})->setName('about.page');


I'm interessted to get route link by name like:
{% get_route('about.page') %}


Is this possible?

Answer

{% is a control structur in twig, Message: Unknown "path_for" tag in "base.twig" at line 39. is display because there is no such tag as control structur definied so twig doesn't know that this is actually a function. So use the output structur in twig {{

{{ path_for('about.page') }}

Btw, path_for uses the function of the router which is $router->pathFor(..)

Comments