Michelle Michelle - 1 year ago 127
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');

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

Is this possible?

Answer Source

{% 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(..)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download