Skip to content

anonymous /index.php
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Expose Slim urlFor to Twig
<?php
// Wrapper function to access urlFor.
function slim_url_for($name, $params = array()) {
return Slim::getInstance()->urlFor($name, $params);
}
// Setup Twig.
TwigView::$twigDirectory = '/path/to/twig/';
// Expose urlFor to Twig.
$view = new TwigView;
$twig = $view->getEnvironment();
$twig->addFunction('url', new Twig_Function_Function('slim_url_for'));
// Setup Slim.
$app = new Slim(array('view' => new TwigView));
// Create a named route.
$app->get('/article/(:id)', function($id) {
// Your logic here.
})->name('article_view');
/*
* In your templates you can now the following code to generate the URL:
* {{ url('article_view', { 'id': article.id }) }}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.