本文整理汇总了PHP中Twig_Template::hasBlock方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Template::hasBlock方法的具体用法?PHP Twig_Template::hasBlock怎么用?PHP Twig_Template::hasBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Template
的用法示例。
在下文中一共展示了Twig_Template::hasBlock方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: populateMessage
/**
* Fills in message using blocks from a template (`body`, `subject`, `from`).
* If there is no `body` block then whole template will be used.
* If there is no `subject` or `from` block then corresponding default value will be used.
* @param \Swift_Message $message
* @param \Twig_Template $templateContent
* @param array $data
*/
protected function populateMessage(\Swift_Message $message, \Twig_Template $templateContent, $data)
{
$body = $templateContent->hasBlock('body') ? $templateContent->renderBlock('body', $data) : $templateContent->render($data);
$subject = $templateContent->hasBlock('subject') ? $templateContent->renderBlock('subject', $data) : $this->defaultSubject;
$from = $templateContent->hasBlock('from') ? $templateContent->renderBlock('from', $data) : $this->defaultFrom;
$message->setFrom($from)->setSubject($subject)->setBody($body, 'text/html', 'utf-8');
}
示例2: renderBlock
/**
* Render block.
*
* @param \Twig_Environment $twig
* @param $name
* @param $parameters
*
* @return string
*/
private function renderBlock(\Twig_Environment $twig, $name, $parameters)
{
// load template if needed
if (is_null($this->template)) {
// get template name
if (is_null($this->theme)) {
$this->theme = 'PlatinumPixsSimplePaginationBundle::blocks.html.twig';
}
$this->template = $twig->loadTemplate($this->theme);
}
if ($this->template->hasBlock($name)) {
return $this->template->renderBlock($name, $parameters);
} else {
throw new \InvalidArgumentException(sprintf('Block "%s" doesn\'t exist in template "%s".', $name, $this->theme));
}
}
示例3: tryToCache
/**
* @param Template $theme
* @param string $block
* @return Template | null
*/
protected function tryToCache(Template $theme, $block)
{
if ($theme->hasBlock($block)) {
$this->cache[$block] = $theme;
return $theme;
}
}
示例4: getBlock
protected function getBlock(\Twig_Template $template, $name)
{
if ($template->hasBlock($name)) {
$blocks = $template->getBlocks();
return $blocks[$name];
} elseif (false !== ($parent = $template->getParent([]))) {
return $this->getBlock($parent, $name);
}
return false;
}
示例5: findTemplateWithBlock
/**
* @param \Twig_Template $template
* @param string $blockName
* @return \Twig_Template|bool
*/
private function findTemplateWithBlock(\Twig_Template $template, $blockName)
{
if ($template->hasBlock($blockName)) {
return $template;
}
// Check parents
if (false !== ($parent = $template->getParent(array()))) {
if ($this->findTemplateWithBlock($parent, $blockName) !== false) {
return $template;
}
}
return false;
}
示例6: findTemplateWithBlock
/**
* @param \Twig_Template $template
* @param string $blockName
*
* @return \Twig_Template|bool
*/
private function findTemplateWithBlock(\Twig_Template $template, $blockName)
{
if ($template->hasBlock($blockName)) {
return $template;
}
if (false === ($parent = $template->getParent([]))) {
return false;
}
if (false !== $this->findTemplateWithBlock($parent, $blockName)) {
return $template;
}
return false;
}