public function Twig_Template::displayBlock in Translation template extractor 7.3
Same name and namespace in other branches
- 6.3 vendor/Twig/Template.php \Twig_Template::displayBlock()
Displays a block.
This method is for internal use only and should never be called directly.
@internal
Parameters
string $name The block name to display:
array $context The context:
array $blocks The current set of blocks:
bool $useBlocks Whether to use the current set of blocks:
1 call to Twig_Template::displayBlock()
- Twig_Template::renderBlock in vendor/
Twig/ Template.php - Renders a block.
File
- vendor/
Twig/ Template.php, line 145
Class
- Twig_Template
- Default base class for compiled templates.
Code
public function displayBlock($name, array $context, array $blocks = array(), $useBlocks = true) {
$name = (string) $name;
if ($useBlocks && isset($blocks[$name])) {
$template = $blocks[$name][0];
$block = $blocks[$name][1];
}
elseif (isset($this->blocks[$name])) {
$template = $this->blocks[$name][0];
$block = $this->blocks[$name][1];
}
else {
$template = null;
$block = null;
}
if (null !== $template) {
// avoid RCEs when sandbox is enabled
if (!$template instanceof self) {
throw new LogicException('A block must be a method on a Twig_Template instance.');
}
try {
$template
->{$block}($context, $blocks);
} catch (Twig_Error $e) {
if (!$e
->getTemplateFile()) {
$e
->setTemplateFile($template
->getTemplateName());
}
// this is mostly useful for Twig_Error_Loader exceptions
// see Twig_Error_Loader
if (false === $e
->getTemplateLine()) {
$e
->setTemplateLine(-1);
$e
->guess();
}
throw $e;
} catch (Exception $e) {
throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e
->getMessage()), -1, $template
->getTemplateName(), $e);
}
}
elseif (false !== ($parent = $this
->getParent($context))) {
$parent
->displayBlock($name, $context, array_merge($this->blocks, $blocks), false);
}
}