本文整理匯總了PHP中Grav\Common\Page\Page::modularTwig方法的典型用法代碼示例。如果您正苦於以下問題:PHP Page::modularTwig方法的具體用法?PHP Page::modularTwig怎麽用?PHP Page::modularTwig使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Grav\Common\Page\Page
的用法示例。
在下文中一共展示了Page::modularTwig方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: processPage
/**
* Twig process that renders a page item. It supports two variations:
* 1) Handles modular pages by rendering a specific page based on its modular twig template
* 2) Renders individual page items for twig processing before the site rendering
*
* @param Page $item The page item to render
* @param string $content Optional content override
* @return string The rendered output
* @throws \Twig_Error_Loader
*/
public function processPage(Page $item, $content = null)
{
$content = $content !== null ? $content : $item->content();
// override the twig header vars for local resolution
$this->grav->fireEvent('onTwigPageVariables');
$twig_vars = $this->twig_vars;
$twig_vars['page'] = $item;
$twig_vars['media'] = $item->media();
$twig_vars['header'] = $item->header();
$local_twig = clone $this->twig;
$modular_twig = $item->modularTwig();
$process_twig = isset($item->header()->process['twig']) ? $item->header()->process['twig'] : false;
try {
// Process Modular Twig
if ($modular_twig) {
$twig_vars['content'] = $content;
$template = $item->template() . TEMPLATE_EXT;
$output = $content = $local_twig->render($template, $twig_vars);
}
// Process in-page Twig
if (!$modular_twig || $modular_twig && $process_twig) {
$name = '@Page:' . $item->path();
$this->setTemplate($name, $content);
$output = $local_twig->render($name, $twig_vars);
}
} catch (\Twig_Error_Loader $e) {
throw new \RuntimeException($e->getRawMessage(), 404, $e);
}
return $output;
}
示例2: processPage
/**
* Twig process that renders a page item. It supports two variations:
* 1) Handles modular pages by rendering a specific page based on its modular twig template
* 2) Renders individual page items for twig processing before the site rendering
*
* @param Page $item The page item to render
* @param string $content Optional content override
* @return string The rendered output
* @throws \Twig_Error_Loader
*/
public function processPage(Page $item, $content = null)
{
$content = $content !== null ? $content : $item->content();
// override the twig header vars for local resolution
$this->grav->fireEvent('onTwigPageVariables');
$twig_vars = $this->twig_vars;
$twig_vars['page'] = $item;
$twig_vars['media'] = $item->media();
$twig_vars['header'] = $item->header();
$local_twig = clone $this->twig;
// Get Twig template layout
if ($item->modularTwig()) {
$twig_vars['content'] = $content;
$template = $item->template() . TEMPLATE_EXT;
$output = $local_twig->render($template, $twig_vars);
} else {
$name = '@Page:' . $item->path();
$this->setTemplate($name, $content);
$output = $local_twig->render($name, $twig_vars);
}
return $output;
}