Create a gist now

Instantly share code, notes, and snippets.

anonymous /index.php
Created Oct 18, 2011

What would you like to do?
Expose Slim urlFor to Twig
// 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.
* In your templates you can now the following code to generate the URL:
* {{ url('article_view', { 'id': }) }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment