ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Twig_Template Class Reference

Default base class for compiled templates. More...

+ Inheritance diagram for Twig_Template:
+ Collaboration diagram for Twig_Template:

Public Member Functions

 __construct (Twig_Environment $env)
 
 __toString ()
 
 getTemplateName ()
 Returns the template name. More...
 
 getDebugInfo ()
 Returns debug information about the template. More...
 
 getSource ()
 Returns the template source code. More...
 
 getSourceContext ()
 Returns information about the original template source code. More...
 
 getEnvironment ()
 
 getParent (array $context)
 Returns the parent template. More...
 
 isTraitable ()
 
 displayParentBlock ($name, array $context, array $blocks=array())
 Displays a parent block. More...
 
 displayBlock ($name, array $context, array $blocks=array(), $useBlocks=true)
 Displays a block. More...
 
 renderParentBlock ($name, array $context, array $blocks=array())
 Renders a parent block. More...
 
 renderBlock ($name, array $context, array $blocks=array(), $useBlocks=true)
 Renders a block. More...
 
 hasBlock ($name, array $context=null, array $blocks=array())
 Returns whether a block exists or not in the current context of the template. More...
 
 getBlockNames (array $context=null, array $blocks=array())
 Returns all block names in the current context of the template. More...
 
 getBlocks ()
 Returns all blocks. More...
 
 display (array $context, array $blocks=array())
 Displays the template with the given context. More...
 
 render (array $context)
 Renders the template with the given context and returns it as string. More...
 
 render (array $context)
 Renders the template with the given context and returns it as string. More...
 
 display (array $context, array $blocks=array())
 Displays the template with the given context. More...
 
 getEnvironment ()
 Returns the bound environment for this template. More...
 

Protected Member Functions

 doGetParent (array $context)
 
 loadTemplate ($template, $templateName=null, $line=null, $index=null)
 
 displayWithErrorHandling (array $context, array $blocks=array())
 
 doDisplay (array $context, array $blocks=array())
 Auto-generated method to display the template with the given context. More...
 
 getContext ($context, $item, $ignoreStrictCheck=false)
 Returns a variable from the context. More...
 
 getAttribute ($object, $item, array $arguments=array(), $type=self::ANY_CALL, $isDefinedTest=false, $ignoreStrictCheck=false)
 Returns the attribute value for a given array/object. More...
 

Protected Attributes

 $parent
 
 $parents = array()
 
 $env
 
 $blocks = array()
 
 $traits = array()
 

Static Protected Attributes

static $cache = array()
 

Additional Inherited Members

- Data Fields inherited from Twig_TemplateInterface
const ANY_CALL = 'any'
 
const ARRAY_CALL = 'array'
 
const METHOD_CALL = 'method'
 

Detailed Description

Default base class for compiled templates.

This class is an implementation detail of how template compilation currently works, which might change. It should never be used directly. Use $twig->load() instead, which returns an instance of Twig_TemplateWrapper.

Author
Fabien Potencier fabie.nosp@m.n@sy.nosp@m.mfony.nosp@m..com

Definition at line 24 of file Template.php.

Constructor & Destructor Documentation

◆ __construct()

Twig_Template::__construct ( Twig_Environment  $env)

Definition at line 37 of file Template.php.

38 {
39 $this->env = $env;
40 }

References $env.

Member Function Documentation

◆ __toString()

Twig_Template::__toString ( )

Definition at line 45 of file Template.php.

46 {
47 return $this->getTemplateName();
48 }
getTemplateName()
Returns the template name.

References getTemplateName().

+ Here is the call graph for this function:

◆ display()

Twig_Template::display ( array  $context,
array  $blocks = array() 
)

Displays the template with the given context.

Parameters
array$contextAn array of parameters to pass to the template
array$blocksAn array of blocks to pass to the template

Implements Twig_TemplateInterface.

Definition at line 401 of file Template.php.

402 {
403 $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks));
404 }
displayWithErrorHandling(array $context, array $blocks=array())
Definition: Template.php:429
$context
Definition: webdav.php:25

References $blocks, $context, and displayWithErrorHandling().

Referenced by render().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ displayBlock()

Twig_Template::displayBlock (   $name,
array  $context,
array  $blocks = array(),
  $useBlocks = true 
)

Displays a block.

This method is for internal use only and should never be called directly.

Parameters
string$nameThe block name to display
array$contextThe context
array$blocksThe current set of blocks
bool$useBlocksWhether to use the current set of blocks

Definition at line 193 of file Template.php.

194 {
195 $name = (string) $name;
196
197 if ($useBlocks && isset($blocks[$name])) {
198 $template = $blocks[$name][0];
199 $block = $blocks[$name][1];
200 } elseif (isset($this->blocks[$name])) {
201 $template = $this->blocks[$name][0];
202 $block = $this->blocks[$name][1];
203 } else {
204 $template = null;
205 $block = null;
206 }
207
208 // avoid RCEs when sandbox is enabled
209 if (null !== $template && !$template instanceof self) {
210 throw new LogicException('A block must be a method on a Twig_Template instance.');
211 }
212
213 if (null !== $template) {
214 try {
215 $template->$block($context, $blocks);
216 } catch (Twig_Error $e) {
217 if (!$e->getSourceContext()) {
218 $e->setSourceContext($template->getSourceContext());
219 }
220
221 // this is mostly useful for Twig_Error_Loader exceptions
222 // see Twig_Error_Loader
223 if (false === $e->getTemplateLine()) {
224 $e->setTemplateLine(-1);
225 $e->guess();
226 }
227
228 throw $e;
229 } catch (Exception $e) {
230 throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getSourceContext(), $e);
231 }
232 } elseif (false !== $parent = $this->getParent($context)) {
233 $parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false);
234 } else {
235 @trigger_error(sprintf('Silent display of undefined block "%s" in template "%s" is deprecated since version 1.29 and will throw an exception in 2.0. Use the "block(\'%s\') is defined" expression to test for block existence.', $name, $this->getTemplateName(), $name), E_USER_DEPRECATED);
236 }
237 }
Exception thrown when an error occurs at runtime.
Definition: Runtime.php:19
Twig base exception.
Definition: Error.php:35
setSourceContext(Twig_Source $source=null)
Sets the source context of the Twig template where the error occurred.
Definition: Error.php:199
setTemplateLine($lineno)
Sets the template line where the error occurred.
Definition: Error.php:179
getSourceContext()
Gets the source context of the Twig template where the error occurred.
Definition: Error.php:191
getTemplateLine()
Gets the template line where the error occurred.
Definition: Error.php:169
getParent(array $context)
Returns the parent template.
Definition: Template.php:115
$template

References $blocks, $context, $name, $parent, $template, getParent(), Twig_Error\getSourceContext(), Twig_Error\getTemplateLine(), getTemplateName(), Twig_Error\guess(), Twig_Error\setSourceContext(), and Twig_Error\setTemplateLine().

Referenced by renderBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ displayParentBlock()

Twig_Template::displayParentBlock (   $name,
array  $context,
array  $blocks = array() 
)

Displays a parent block.

This method is for internal use only and should never be called directly.

Parameters
string$nameThe block name to display from the parent
array$contextThe context
array$blocksThe current set of blocks

Definition at line 167 of file Template.php.

168 {
169 $name = (string) $name;
170
171 if (isset($this->traits[$name])) {
172 $this->traits[$name][0]->displayBlock($name, $context, $blocks, false);
173 } elseif (false !== $parent = $this->getParent($context)) {
174 $parent->displayBlock($name, $context, $blocks, false);
175 } else {
176 throw new Twig_Error_Runtime(sprintf('The template has no parent and no traits defining the "%s" block.', $name), -1, $this->getSourceContext());
177 }
178 }
getSourceContext()
Returns information about the original template source code.
Definition: Template.php:88

References $blocks, $context, $name, $parent, getParent(), and getSourceContext().

Referenced by renderParentBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ displayWithErrorHandling()

Twig_Template::displayWithErrorHandling ( array  $context,
array  $blocks = array() 
)
protected

Definition at line 429 of file Template.php.

430 {
431 try {
432 $this->doDisplay($context, $blocks);
433 } catch (Twig_Error $e) {
434 if (!$e->getSourceContext()) {
436 }
437
438 // this is mostly useful for Twig_Error_Loader exceptions
439 // see Twig_Error_Loader
440 if (false === $e->getTemplateLine()) {
441 $e->setTemplateLine(-1);
442 $e->guess();
443 }
444
445 throw $e;
446 } catch (Exception $e) {
447 throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e);
448 }
449 }
doDisplay(array $context, array $blocks=array())
Auto-generated method to display the template with the given context.

References $blocks, doDisplay(), Twig_Error\getSourceContext(), getSourceContext(), Twig_Error\getTemplateLine(), Twig_Error\guess(), Twig_Error\setSourceContext(), and Twig_Error\setTemplateLine().

Referenced by display().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doDisplay()

Twig_Template::doDisplay ( array  $context,
array  $blocks = array() 
)
abstractprotected

Auto-generated method to display the template with the given context.

Parameters
array$contextAn array of parameters to pass to the template
array$blocksAn array of blocks to pass to the template

Reimplemented in Twig_TemplateTest.

Referenced by displayWithErrorHandling().

+ Here is the caller graph for this function:

◆ doGetParent()

Twig_Template::doGetParent ( array  $context)
protected

Reimplemented in Twig_TemplateTest.

Definition at line 145 of file Template.php.

146 {
147 return false;
148 }

Referenced by getParent().

+ Here is the caller graph for this function:

◆ getAttribute()

Twig_Template::getAttribute (   $object,
  $item,
array  $arguments = array(),
  $type = self::ANY_CALL,
  $isDefinedTest = false,
  $ignoreStrictCheck = false 
)
protected

Returns the attribute value for a given array/object.

Parameters
mixed$objectThe object or array from where to get the item
mixed$itemThe item to get from the array or object
array$argumentsAn array of arguments to pass if the item is an object method
string$typeThe type of attribute (
See also
Twig_Template constants)
Parameters
bool$isDefinedTestWhether this is only a defined check
bool$ignoreStrictCheckWhether to ignore the strict attribute check or not
Returns
mixed The attribute value, or a Boolean when $isDefinedTest is true, or null when the attribute is not set and $ignoreStrictCheck is true
Exceptions
Twig_Error_Runtimeif the attribute does not exist and Twig is running in strict mode and $isDefinedTest is false

Reimplemented in Twig_TemplateTest.

Definition at line 509 of file Template.php.

510 {
511 // array
512 if (self::METHOD_CALL !== $type) {
513 $arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item;
514
515 if ((is_array($object) && (isset($object[$arrayItem]) || array_key_exists($arrayItem, $object)))
516 || ($object instanceof ArrayAccess && isset($object[$arrayItem]))
517 ) {
518 if ($isDefinedTest) {
519 return true;
520 }
521
522 return $object[$arrayItem];
523 }
524
525 if (self::ARRAY_CALL === $type || !is_object($object)) {
526 if ($isDefinedTest) {
527 return false;
528 }
529
530 if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
531 return;
532 }
533
534 if ($object instanceof ArrayAccess) {
535 $message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, get_class($object));
536 } elseif (is_object($object)) {
537 $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, get_class($object));
538 } elseif (is_array($object)) {
539 if (empty($object)) {
540 $message = sprintf('Key "%s" does not exist as the array is empty.', $arrayItem);
541 } else {
542 $message = sprintf('Key "%s" for array with keys "%s" does not exist.', $arrayItem, implode(', ', array_keys($object)));
543 }
544 } elseif (self::ARRAY_CALL === $type) {
545 if (null === $object) {
546 $message = sprintf('Impossible to access a key ("%s") on a null variable.', $item);
547 } else {
548 $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s").', $item, gettype($object), $object);
549 }
550 } elseif (null === $object) {
551 $message = sprintf('Impossible to access an attribute ("%s") on a null variable.', $item);
552 } else {
553 $message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s").', $item, gettype($object), $object);
554 }
555
556 throw new Twig_Error_Runtime($message, -1, $this->getSourceContext());
557 }
558 }
559
560 if (!is_object($object)) {
561 if ($isDefinedTest) {
562 return false;
563 }
564
565 if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
566 return;
567 }
568
569 if (null === $object) {
570 $message = sprintf('Impossible to invoke a method ("%s") on a null variable.', $item);
571 } elseif (is_array($object)) {
572 $message = sprintf('Impossible to invoke a method ("%s") on an array.', $item);
573 } else {
574 $message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s").', $item, gettype($object), $object);
575 }
576
577 throw new Twig_Error_Runtime($message, -1, $this->getSourceContext());
578 }
579
580 // object property
581 if (self::METHOD_CALL !== $type && !$object instanceof self) { // Twig_Template does not have public properties, and we don't want to allow access to internal ones
582 if (isset($object->$item) || array_key_exists((string) $item, $object)) {
583 if ($isDefinedTest) {
584 return true;
585 }
586
587 if ($this->env->hasExtension('Twig_Extension_Sandbox')) {
588 $this->env->getExtension('Twig_Extension_Sandbox')->checkPropertyAllowed($object, $item);
589 }
590
591 return $object->$item;
592 }
593 }
594
595 $class = get_class($object);
596
597 // object method
598 if (!isset(self::$cache[$class])) {
599 // get_class_methods returns all methods accessible in the scope, but we only want public ones to be accessible in templates
600 if ($object instanceof self) {
601 $ref = new ReflectionClass($class);
602 $methods = array();
603
604 foreach ($ref->getMethods(ReflectionMethod::IS_PUBLIC) as $refMethod) {
605 // Accessing the environment from templates is forbidden to prevent untrusted changes to the environment
606 if ('getenvironment' !== strtolower($refMethod->name)) {
607 $methods[] = $refMethod->name;
608 }
609 }
610 } else {
611 $methods = get_class_methods($object);
612 }
613 // sort values to have consistent behavior, so that "get" methods win precedence over "is" methods
614 sort($methods);
615
616 $cache = array();
617
618 foreach ($methods as $method) {
619 $cache[$method] = $method;
620 $cache[$lcName = strtolower($method)] = $method;
621
622 if ('g' === $lcName[0] && 0 === strpos($lcName, 'get')) {
623 $name = substr($method, 3);
624 $lcName = substr($lcName, 3);
625 } elseif ('i' === $lcName[0] && 0 === strpos($lcName, 'is')) {
626 $name = substr($method, 2);
627 $lcName = substr($lcName, 2);
628 } else {
629 continue;
630 }
631
632 // skip get() and is() methods (in which case, $name is empty)
633 if ($name) {
634 if (!isset($cache[$name])) {
635 $cache[$name] = $method;
636 }
637 if (!isset($cache[$lcName])) {
638 $cache[$lcName] = $method;
639 }
640 }
641 }
642 self::$cache[$class] = $cache;
643 }
644
645 $call = false;
646 if (isset(self::$cache[$class][$item])) {
647 $method = self::$cache[$class][$item];
648 } elseif (isset(self::$cache[$class][$lcItem = strtolower($item)])) {
649 $method = self::$cache[$class][$lcItem];
650 } elseif (isset(self::$cache[$class]['__call'])) {
651 $method = $item;
652 $call = true;
653 } else {
654 if ($isDefinedTest) {
655 return false;
656 }
657
658 if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
659 return;
660 }
661
662 throw new Twig_Error_Runtime(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%1$s()"/"is%1$s()" or "__call()" exist and have public access in class "%2$s".', $item, $class), -1, $this->getSourceContext());
663 }
664
665 if ($isDefinedTest) {
666 return true;
667 }
668
669 if ($this->env->hasExtension('Twig_Extension_Sandbox')) {
670 $this->env->getExtension('Twig_Extension_Sandbox')->checkMethodAllowed($object, $method);
671 }
672
673 // Some objects throw exceptions when they have __call, and the method we try
674 // to call is not supported. If ignoreStrictCheck is true, we should return null.
675 try {
676 if (!$arguments) {
677 $ret = $object->$method();
678 } else {
679 $ret = call_user_func_array(array($object, $method), $arguments);
680 }
681 } catch (BadMethodCallException $e) {
682 if ($call && ($ignoreStrictCheck || !$this->env->isStrictVariables())) {
683 return;
684 }
685 throw $e;
686 }
687
688 // @deprecated in 1.28
689 if ($object instanceof Twig_TemplateInterface) {
690 $self = $object->getTemplateName() === $this->getTemplateName();
691 $message = sprintf('Calling "%s" on template "%s" from template "%s" is deprecated since version 1.28 and won\'t be supported anymore in 2.0.', $item, $object->getTemplateName(), $this->getTemplateName());
692 if ('renderBlock' === $method || 'displayBlock' === $method) {
693 $message .= sprintf(' Use block("%s"%s) instead).', $arguments[0], $self ? '' : ', template');
694 } elseif ('hasBlock' === $method) {
695 $message .= sprintf(' Use "block("%s"%s) is defined" instead).', $arguments[0], $self ? '' : ', template');
696 } elseif ('render' === $method || 'display' === $method) {
697 $message .= sprintf(' Use include("%s") instead).', $object->getTemplateName());
698 }
699 @trigger_error($message, E_USER_DEPRECATED);
700
701 return '' === $ret ? '' : new Twig_Markup($ret, $this->env->getCharset());
702 }
703
704 return $ret;
705 }
Marks a content as safe.
Definition: Markup.php:18
static $cache
Definition: Template.php:29
Interface implemented by all compiled templates.
catch(Exception $e) $message
$ret
Definition: parser.php:6
$type

References $cache, $message, $name, $ret, $type, getSourceContext(), and getTemplateName().

+ Here is the call graph for this function:

◆ getBlockNames()

Twig_Template::getBlockNames ( array  $context = null,
array  $blocks = array() 
)

Returns all block names in the current context of the template.

This method checks blocks defined in the current template or defined in "used" traits or defined in parent templates.

Parameters
array$contextThe context
array$blocksThe current set of blocks
Returns
array An array of block names

Definition at line 334 of file Template.php.

335 {
336 if (null === $context) {
337 @trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', E_USER_DEPRECATED);
338
339 return array_keys($this->blocks);
340 }
341
342 $names = array_merge(array_keys($blocks), array_keys($this->blocks));
343
344 if (false !== $parent = $this->getParent($context)) {
345 $names = array_merge($names, $parent->getBlockNames($context));
346 }
347
348 return array_unique($names);
349 }

References $blocks, $context, $parent, and getParent().

+ Here is the call graph for this function:

◆ getBlocks()

Twig_Template::getBlocks ( )

Returns all blocks.

This method is for internal use only and should never be called directly.

Returns
array An array of blocks

Definition at line 396 of file Template.php.

397 {
398 return $this->blocks;
399 }

References $blocks.

◆ getContext()

Twig_Template::getContext (   $context,
  $item,
  $ignoreStrictCheck = false 
)
finalprotected

Returns a variable from the context.

This method is for internal use only and should never be called directly.

This method should not be overridden in a sub-class as this is an implementation detail that has been introduced to optimize variable access for versions of PHP before 5.4. This is not a way to override the way to get a variable value.

Parameters
array$contextThe context
string$itemThe variable to return from the context
bool$ignoreStrictCheckWhether to ignore the strict variable check or not
Returns
mixed The content of the context variable
Exceptions
Twig_Error_Runtimeif the variable does not exist and Twig is running in strict mode

Definition at line 480 of file Template.php.

481 {
482 if (!array_key_exists($item, $context)) {
483 if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
484 return;
485 }
486
487 throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist.', $item), -1, $this->getSourceContext());
488 }
489
490 return $context[$item];
491 }

References $context, and getSourceContext().

+ Here is the call graph for this function:

◆ getDebugInfo()

Twig_Template::getDebugInfo ( )

Returns debug information about the template.

Returns
array Debug information

Reimplemented in Twig_TemplateTest.

Definition at line 64 of file Template.php.

65 {
66 return array();
67 }

◆ getEnvironment()

Twig_Template::getEnvironment ( )
Deprecated:
since 1.20 (to be removed in 2.0)

Implements Twig_TemplateInterface.

Definition at line 96 of file Template.php.

97 {
98 @trigger_error('The '.__METHOD__.' method is deprecated since version 1.20 and will be removed in 2.0.', E_USER_DEPRECATED);
99
100 return $this->env;
101 }

References $env.

◆ getParent()

Twig_Template::getParent ( array  $context)

Returns the parent template.

This method is for internal use only and should never be called directly.

Parameters
array$context
Returns
Twig_TemplateInterface|false The parent template or false if there is no parent

Definition at line 115 of file Template.php.

116 {
117 if (null !== $this->parent) {
118 return $this->parent;
119 }
120
121 try {
122 $parent = $this->doGetParent($context);
123
124 if (false === $parent) {
125 return false;
126 }
127
128 if ($parent instanceof self) {
129 return $this->parents[$parent->getTemplateName()] = $parent;
130 }
131
132 if (!isset($this->parents[$parent])) {
133 $this->parents[$parent] = $this->loadTemplate($parent);
134 }
135 } catch (Twig_Error_Loader $e) {
136 $e->setSourceContext(null);
137 $e->guess();
138
139 throw $e;
140 }
141
142 return $this->parents[$parent];
143 }
Exception thrown when an error occurs during template loading.
Definition: Loader.php:26
loadTemplate($template, $templateName=null, $line=null, $index=null)
Definition: Template.php:351
doGetParent(array $context)
Definition: Template.php:145

References $parent, doGetParent(), Twig_Error\guess(), loadTemplate(), and Twig_Error\setSourceContext().

Referenced by displayBlock(), displayParentBlock(), getBlockNames(), and hasBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSource()

Twig_Template::getSource ( )

Returns the template source code.

Returns
string The template source code
Deprecated:
since 1.27 (to be removed in 2.0). Use getSourceContext() instead

Definition at line 76 of file Template.php.

77 {
78 @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED);
79
80 return '';
81 }

◆ getSourceContext()

Twig_Template::getSourceContext ( )

Returns information about the original template source code.

Returns
Twig_Source

Definition at line 88 of file Template.php.

89 {
90 return new Twig_Source('', $this->getTemplateName());
91 }
Holds information about a non-compiled Twig template.
Definition: Source.php:20

References getTemplateName().

Referenced by displayParentBlock(), displayWithErrorHandling(), getAttribute(), getContext(), and loadTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTemplateName()

Twig_Template::getTemplateName ( )
abstract

Returns the template name.

Returns
string The template name

Reimplemented in Twig_TemplateTest.

Referenced by __toString(), displayBlock(), getAttribute(), and getSourceContext().

+ Here is the caller graph for this function:

◆ hasBlock()

Twig_Template::hasBlock (   $name,
array  $context = null,
array  $blocks = array() 
)

Returns whether a block exists or not in the current context of the template.

This method checks blocks defined in the current template or defined in "used" traits or defined in parent templates.

Parameters
string$nameThe block name
array$contextThe context
array$blocksThe current set of blocks
Returns
bool true if the block exists, false otherwise

Definition at line 298 of file Template.php.

299 {
300 if (null === $context) {
301 @trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', E_USER_DEPRECATED);
302
303 return isset($this->blocks[(string) $name]);
304 }
305
306 if (isset($blocks[$name])) {
307 return $blocks[$name][0] instanceof self;
308 }
309
310 if (isset($this->blocks[$name])) {
311 return true;
312 }
313
314 if (false !== $parent = $this->getParent($context)) {
315 return $parent->hasBlock($name, $context);
316 }
317
318 return false;
319 }

References $blocks, $context, $name, $parent, and getParent().

+ Here is the call graph for this function:

◆ isTraitable()

Twig_Template::isTraitable ( )

Definition at line 150 of file Template.php.

151 {
152 return true;
153 }

◆ loadTemplate()

Twig_Template::loadTemplate (   $template,
  $templateName = null,
  $line = null,
  $index = null 
)
protected

Definition at line 351 of file Template.php.

352 {
353 try {
354 if (is_array($template)) {
355 return $this->env->resolveTemplate($template);
356 }
357
358 if ($template instanceof self) {
359 return $template;
360 }
361
362 if ($template instanceof Twig_TemplateWrapper) {
363 return $template;
364 }
365
366 return $this->env->loadTemplate($template, $index);
367 } catch (Twig_Error $e) {
368 if (!$e->getSourceContext()) {
369 $e->setSourceContext($templateName ? new Twig_Source('', $templateName) : $this->getSourceContext());
370 }
371
372 if ($e->getTemplateLine()) {
373 throw $e;
374 }
375
376 if (!$line) {
377 $e->guess();
378 } else {
379 $e->setTemplateLine($line);
380 }
381
382 throw $e;
383 }
384 }
Exposes a template to userland.
$index
Definition: metadata.php:60

References $index, $template, Twig_Error\getSourceContext(), getSourceContext(), Twig_Error\getTemplateLine(), Twig_Error\guess(), Twig_Error\setSourceContext(), and Twig_Error\setTemplateLine().

Referenced by getParent(), and Twig_Tests_Node_ModuleTest\getTests().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ render()

Twig_Template::render ( array  $context)

Renders the template with the given context and returns it as string.

Parameters
array$contextAn array of parameters to pass to the template
Returns
string The rendered template

Implements Twig_TemplateInterface.

Definition at line 406 of file Template.php.

407 {
408 $level = ob_get_level();
409 ob_start();
410 try {
411 $this->display($context);
412 } catch (Exception $e) {
413 while (ob_get_level() > $level) {
414 ob_end_clean();
415 }
416
417 throw $e;
418 } catch (Throwable $e) {
419 while (ob_get_level() > $level) {
420 ob_end_clean();
421 }
422
423 throw $e;
424 }
425
426 return ob_get_clean();
427 }
display(array $context, array $blocks=array())
Displays the template with the given context.
Definition: Template.php:401

References display().

+ Here is the call graph for this function:

◆ renderBlock()

Twig_Template::renderBlock (   $name,
array  $context,
array  $blocks = array(),
  $useBlocks = true 
)

Renders a block.

This method is for internal use only and should never be called directly.

Parameters
string$nameThe block name to render
array$contextThe context
array$blocksThe current set of blocks
bool$useBlocksWhether to use the current set of blocks
Returns
string The rendered block

Definition at line 276 of file Template.php.

277 {
278 ob_start();
279 $this->displayBlock($name, $context, $blocks, $useBlocks);
280
281 return ob_get_clean();
282 }
displayBlock($name, array $context, array $blocks=array(), $useBlocks=true)
Displays a block.
Definition: Template.php:193

References $blocks, $name, and displayBlock().

+ Here is the call graph for this function:

◆ renderParentBlock()

Twig_Template::renderParentBlock (   $name,
array  $context,
array  $blocks = array() 
)

Renders a parent block.

This method is for internal use only and should never be called directly.

Parameters
string$nameThe block name to render from the parent
array$contextThe context
array$blocksThe current set of blocks
Returns
string The rendered block

Definition at line 253 of file Template.php.

254 {
255 ob_start();
257
258 return ob_get_clean();
259 }
displayParentBlock($name, array $context, array $blocks=array())
Displays a parent block.
Definition: Template.php:167

References $blocks, $name, and displayParentBlock().

+ Here is the call graph for this function:

Field Documentation

◆ $blocks

Twig_Template::$blocks = array()
protected

◆ $cache

Twig_Template::$cache = array()
staticprotected

Definition at line 29 of file Template.php.

Referenced by getAttribute().

◆ $env

Twig_Template::$env
protected

Definition at line 33 of file Template.php.

Referenced by __construct(), Twig_TemplateTest\__construct(), and getEnvironment().

◆ $parent

Twig_Template::$parent
protected

Definition at line 31 of file Template.php.

Referenced by displayBlock(), displayParentBlock(), getBlockNames(), getParent(), and hasBlock().

◆ $parents

Twig_Template::$parents = array()
protected

Definition at line 32 of file Template.php.

◆ $traits

Twig_Template::$traits = array()
protected

Definition at line 35 of file Template.php.


The documentation for this class was generated from the following file: