Loads a template by name.
public loadTemplate ( string $name ) : Twig_TemplateInterface | ||
$name | string | The template name |
return | Twig_TemplateInterface | A template instance representing the given template name |
$loader = new Twig_Loader_Filesystem('templates'); $twig = new Twig_Environment($loader); $template = $twig->loadTemplate('example.twig'); echo $template->render(array('name' => 'World'));
$twig = new Twig_Environment(); $template = $twig->loadTemplate('{{ name }}'); echo $template->render(array('name' => 'World'));
$loader = new Twig_Loader_Filesystem(array( 'templates', 'templates/mobile', )); $twig = new Twig_Environment($loader); // load a template from the "mobile" namespace $template = $twig->loadTemplate('@mobile/example.twig'); echo $template->render(array('name' => 'World'));Overall, Twig is a highly extensible and flexible template engine, which has become an essential part of the PHP ecosystem. The code examples above demonstrate some of the basic features of the Twig_Environment loadTemplate method and the Twig library as a whole.
public loadTemplate ( string $name ) : Twig_TemplateInterface | ||
$name | string | The template name |
return | Twig_TemplateInterface | A template instance representing the given template name |