Last active
August 29, 2015 13:57
-
-
Save wkjagt/9368879 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// setup a template loader used by Twig to load the template strings. Most common is loading | |
// templates from the file system. This loader needs takes a template path or an array of | |
// template paths as argument to its constructor. | |
$templatePath = __DIR__.'/templates'; | |
$loader = new Twig_Loader_Filesystem($templatePath); | |
// setup the twig environment. This is used for the actual rendering. The Twig environment takes | |
// the loader and an array of options as its arguments. In this example I use the twig environment | |
// directly but in the context of a framework it would be made available to the logic that uses it, | |
// for example through a dependency injection container. | |
$options = array( | |
'cache' => __DIR__.'/template-cache', | |
// other options here | |
); | |
$twigEnv = new Twig_Environment($loader, $options); | |
// adding extenstions to Twig. | |
$twigEnv->addExtension(new MyTwigExtension); | |
// using the Twig Environment to render templates. | |
$templateVars = array('foo' => 'bar'); | |
$html = $twigEnv->('a-template.html.twig', $templateVars); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment