本文整理匯總了PHP中Twig_Template::getEnvironment方法的典型用法代碼示例。如果您正苦於以下問題:PHP Twig_Template::getEnvironment方法的具體用法?PHP Twig_Template::getEnvironment怎麽用?PHP Twig_Template::getEnvironment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Twig_Template
的用法示例。
在下文中一共展示了Twig_Template::getEnvironment方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: renderTwigBlock
protected function renderTwigBlock(\Twig_Template $template, $blockName, $context = array())
{
foreach ($template->getEnvironment()->getGlobals() as $key => $value) {
if (!array_key_exists($key, $context)) {
$context[$key] = $value;
}
}
return $template->renderBlock($blockName, $context);
}
示例2: renderBlock
/**
* Renders a Twig block.
*
* see {@link https://github.com/twigphp/Twig/issues/676#issuecomment-15842093}
*
* @param \Twig_Template $template
* @param string $block
* @param array $context
*
* @return string
*
* @throws \Exception
*/
private function renderBlock(\Twig_Template $template, $block, array $context)
{
$context = $template->getEnvironment()->mergeGlobals($context);
$level = ob_get_level();
ob_start();
try {
$rendered = $template->renderBlock($block, $context);
ob_end_clean();
return $rendered;
} catch (\Exception $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
}
}
示例3: addGlobalContext
/**
* Adds a global to the template
*
* @param string $name
* @param mixed $value
*/
public function addGlobalContext($name, $value)
{
$this->template->getEnvironment()->addGlobal($name, $value);
}