Twig_Environment::setLoader PHP Method

setLoader() public method

Sets the Loader instance.
public setLoader ( Twig_LoaderInterface $loader )
$loader Twig_LoaderInterface A Twig_LoaderInterface instance
    public function setLoader(Twig_LoaderInterface $loader)
    {
        $this->loader = $loader;
    }

Usage Example

 /**
  * Render a string
  *
  * A special option in the $locals array can be used to define the Twital adapter to use.
  * The array key is `__twital-adapter`, and the value is an instance of `\Goetas\Twital\SourceAdapter`
  *
  * @param string $template The template content to render
  * @param array $locals The variable to use in template
  * @return null|string
  *
  * @throws \Twig_Error_Loader
  * @throws \Twig_Error_Runtime
  * @throws \Twig_Error_Syntax
  */
 public function render($template, array $locals = array())
 {
     if (array_key_exists('__twital-adapter', $locals)) {
         $this->stringLoader->addSourceAdapter('/.*/', $locals['__twital-adapter']);
     }
     // Render the file using the straight string.
     $this->environment->setLoader($this->stringLoader);
     return $this->environment->render($template, $locals);
 }
All Usage Examples Of Twig_Environment::setLoader