Twig_TemplateWrapper

Exposes a template to userland.

Defined (1)

The class is defined in the following location(s).

/vendor/twig/twig/lib/Twig/TemplateWrapper.php  
  1. final class Twig_TemplateWrapper 
  2. private $env; 
  3. private $template; 
  4.  
  5. /** 
  6. * This method is for internal use only and should never be called 
  7. * directly (use Twig_Environment::load() instead). 
  8. * @internal 
  9. */ 
  10. public function __construct(Twig_Environment $env, Twig_Template $template) 
  11. $this->env = $env; 
  12. $this->template = $template; 
  13.  
  14. /** 
  15. * Renders the template. 
  16. * @param array $context An array of parameters to pass to the template 
  17. * @return string The rendered template 
  18. */ 
  19. public function render($context = array()) 
  20. return $this->template->render($context); 
  21.  
  22. /** 
  23. * Displays the template. 
  24. * @param array $context An array of parameters to pass to the template 
  25. */ 
  26. public function display($context = array()) 
  27. $this->template->display($context); 
  28.  
  29. /** 
  30. * Checks if a block is defined. 
  31. * @param string $name The block name 
  32. * @param array $context An array of parameters to pass to the template 
  33. * @return bool 
  34. */ 
  35. public function hasBlock($name, $context = array()) 
  36. return $this->template->hasBlock($name, $context); 
  37.  
  38. /** 
  39. * Returns defined block names in the template. 
  40. * @param array $context An array of parameters to pass to the template 
  41. * @return string[] An array of defined template block names 
  42. */ 
  43. public function getBlockNames($context = array()) 
  44. return $this->template->getBlockNames($context); 
  45.  
  46. /** 
  47. * Renders a template block. 
  48. * @param string $name The block name to render 
  49. * @param array $context An array of parameters to pass to the template 
  50. * @return string The rendered block 
  51. */ 
  52. public function renderBlock($name, $context = array()) 
  53. $context = $this->env->mergeGlobals($context); 
  54. $level = ob_get_level(); 
  55. ob_start(); 
  56. try { 
  57. $this->template->displayBlock($name, $context); 
  58. } catch (Exception $e) { 
  59. while (ob_get_level() > $level) { 
  60. ob_end_clean(); 
  61.  
  62. throw $e; 
  63. } catch (Throwable $e) { 
  64. while (ob_get_level() > $level) { 
  65. ob_end_clean(); 
  66.  
  67. throw $e; 
  68.  
  69. return ob_get_clean(); 
  70.  
  71. /** 
  72. * Displays a template block. 
  73. * @param string $name The block name to render 
  74. * @param array $context An array of parameters to pass to the template 
  75. */ 
  76. public function displayBlock($name, $context = array()) 
  77. $this->template->displayBlock($name, $this->env->mergeGlobals($context)); 
  78.  
  79. /** 
  80. * @return Twig_Source 
  81. */ 
  82. public function getSourceContext() 
  83. return $this->template->getSourceContext();