当前位置: 首页>>代码示例>>PHP>>正文


PHP Page::template方法代码示例

本文整理汇总了PHP中Grav\Common\Page\Page::template方法的典型用法代码示例。如果您正苦于以下问题:PHP Page::template方法的具体用法?PHP Page::template怎么用?PHP Page::template使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Grav\Common\Page\Page的用法示例。


在下文中一共展示了Page::template方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onPageInitialized

 /**
  * Create search result page.
  */
 public function onPageInitialized()
 {
     $page = new Page();
     $page->init(new \SplFileInfo(__DIR__ . '/pages/simplesearch.md'));
     // override the template is set in the config
     $template_override = $this->config->get('plugins.simplesearch.template');
     if ($template_override) {
         $page->template($template_override);
     }
     $this->grav['page'] = $page;
 }
开发者ID:shahriyarahmed31,项目名称:docs,代码行数:14,代码来源:simplesearch.php

示例2: onPagesInitialized

 /**
  * Build search results.
  */
 public function onPagesInitialized()
 {
     $page = $this->grav['page'];
     // If a page exists merge the configs
     if ($page) {
         $this->config->set('plugins.simplesearch', $this->mergeConfig($page));
     }
     /** @var Uri $uri */
     $uri = $this->grav['uri'];
     $query = $uri->param('query') ?: $uri->query('query');
     $route = $this->config->get('plugins.simplesearch.route');
     // performance check
     if ($route && $query && $route == $uri->path()) {
         $this->enable(['onTwigSiteVariables' => ['onTwigSiteVariables', 0]]);
     } else {
         return;
     }
     $this->query = explode(',', $query);
     /** @var Taxonomy $taxonomy_map */
     $taxonomy_map = $this->grav['taxonomy'];
     $taxonomies = [];
     $filters = (array) $this->config->get('plugins.simplesearch.filters');
     $operator = $this->config->get('plugins.simplesearch.filter_combinator', 'and');
     // see if the filter uses the new 'items-type' syntax
     $new_approach = false;
     foreach ($filters as $filter) {
         $filter_saved = $filter;
         if (is_array($filter)) {
             $filter = key($filter);
         }
         if (Utils::startsWith($filter, '@')) {
             if ($filter == '@self') {
                 $new_approach = true;
             }
             if ($filter == '@taxonomy') {
                 $taxonomies = $filter_saved[$filter];
             }
         }
     }
     if ($new_approach) {
         $params = $page->header()->content;
         $params['query'] = $this->config->get('plugins.simplesearch.query');
         $this->collection = $page->collection($params, false);
     } else {
         $this->collection = new Collection();
         $this->collection->append($taxonomy_map->findTaxonomy($filters, $operator)->toArray());
     }
     $extras = [];
     /** @var Page $cpage */
     foreach ($this->collection as $cpage) {
         foreach ($this->query as $query) {
             $query = trim($query);
             $taxonomy_match = false;
             if (!empty($taxonomies)) {
                 $page_taxonomies = $cpage->taxonomy();
                 foreach ((array) $taxonomies as $taxonomy) {
                     if (array_key_exists($taxonomy, $page_taxonomies)) {
                         $taxonomy_values = implode('|', $page_taxonomies[$taxonomy]);
                         if (stripos($taxonomy_values, $query) !== false) {
                             $taxonomy_match = true;
                             break;
                         }
                     }
                 }
             }
             if ($taxonomy_match === false && stripos($cpage->content(), $query) === false && stripos($cpage->title(), $query) === false) {
                 $this->collection->remove($cpage);
                 continue;
             }
             if ($cpage->modular()) {
                 $this->collection->remove($cpage);
                 $parent = $cpage->parent();
                 $extras[$parent->path()] = ['slug' => $parent->slug()];
             }
         }
     }
     if (!empty($extras)) {
         $this->collection->append($extras);
     }
     // use a configured sorting order if not already done
     if (!$new_approach) {
         $this->collection = $this->collection->order($this->config->get('plugins.simplesearch.order.by'), $this->config->get('plugins.simplesearch.order.dir'));
     }
     // if page doesn't have settings set, create a page
     if (!isset($page->header()->simplesearch)) {
         // create the search page
         $page = new Page();
         $page->init(new \SplFileInfo(__DIR__ . '/pages/simplesearch.md'));
         // override the template is set in the config
         $template_override = $this->config->get('plugins.simplesearch.template');
         if ($template_override) {
             $page->template($template_override);
         }
         // fix RuntimeException: Cannot override frozen service "page" issue
         unset($this->grav['page']);
         $this->grav['page'] = $page;
     }
//.........这里部分代码省略.........
开发者ID:retsoced,项目名称:grav-plugin-simplesearch,代码行数:101,代码来源:simplesearch.php

示例3: 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;
 }
开发者ID:sunilkgrao,项目名称:grav-test,代码行数:40,代码来源:Twig.php

示例4: addRegisterPage

 /**
  * Add Register page
  */
 public function addRegisterPage()
 {
     $route = $this->config->get('plugins.login.route_register');
     /** @var Pages $pages */
     $pages = $this->grav['pages'];
     $page = new Page();
     $page->init(new \SplFileInfo(__DIR__ . "/pages/register.md"));
     $page->template('form');
     $page->slug(basename($route));
     $pages->addPage($page, $route);
 }
开发者ID:allencloud,项目名称:daocloud-docs,代码行数:14,代码来源:login.php

示例5: preparePage

 /**
  * Prepare a page to be stored: update its folder, name, template, header and content
  *
  * @param \Grav\Common\Page\Page $page
  * @param bool                   $clean_header
  */
 protected function preparePage(\Grav\Common\Page\Page $page, $clean_header = false, $language = null)
 {
     $input = $this->post;
     if (isset($input['order'])) {
         $order = max(0, (int) isset($input['order']) ? $input['order'] : $page->value('order'));
         $ordering = $order ? sprintf('%02d.', $order) : '';
         $slug = empty($input['folder']) ? $page->value('folder') : (string) $input['folder'];
         $page->folder($ordering . $slug);
     }
     if (isset($input['name']) && !empty($input['name'])) {
         $type = (string) strtolower($input['name']);
         $name = preg_replace('|.*/|', '', $type);
         if ($language) {
             $name .= '.' . $language;
         } else {
             $language = $this->grav['language'];
             if ($language->enabled()) {
                 $name .= '.' . $language->getLanguage();
             }
         }
         $name .= '.md';
         $page->name($name);
         $page->template($type);
         // unset some header things, template for now as we've just set that
         if (isset($input['header']['template'])) {
             unset($input['header']['template']);
         }
     }
     // Special case for Expert mode: build the raw, unset content
     if (isset($input['frontmatter']) && isset($input['content'])) {
         $page->raw("---\n" . (string) $input['frontmatter'] . "\n---\n" . (string) $input['content']);
         unset($input['content']);
     }
     if (isset($input['header'])) {
         $header = $input['header'];
         foreach ($header as $key => $value) {
             if ($key == 'metadata') {
                 foreach ($header['metadata'] as $key2 => $value2) {
                     if (isset($input['toggleable_header']['metadata'][$key2]) && !$input['toggleable_header']['metadata'][$key2]) {
                         $header['metadata'][$key2] = '';
                     }
                 }
             } elseif ($key == 'taxonomy') {
                 foreach ($header[$key] as $taxkey => $taxonomy) {
                     if (is_array($taxonomy) && count($taxonomy) == 1 && trim($taxonomy[0]) == '') {
                         unset($header[$key][$taxkey]);
                     }
                 }
             } else {
                 if (isset($input['toggleable_header'][$key]) && !$input['toggleable_header'][$key]) {
                     $header[$key] = null;
                 }
             }
         }
         if ($clean_header) {
             $header = Utils::arrayFilterRecursive($header, function ($k, $v) {
                 return !(is_null($v) || $v === '');
             });
         }
         $page->header((object) $header);
         $page->frontmatter(Yaml::dump((array) $page->header()));
     }
     // Fill content last because it also renders the output.
     if (isset($input['content'])) {
         $page->rawMarkdown((string) $input['content']);
     }
 }
开发者ID:clee03,项目名称:metal,代码行数:73,代码来源:controller.php

示例6: onPagesInitialized

 /**
  * Build search results.
  */
 public function onPagesInitialized()
 {
     $page = $this->grav['page'];
     // If a page exists merge the configs
     if ($page) {
         $this->config->set('plugins.simplesearch', $this->mergeConfig($page));
     }
     /** @var Uri $uri */
     $uri = $this->grav['uri'];
     $query = $uri->param('query') ?: $uri->query('query');
     $route = $this->config->get('plugins.simplesearch.route');
     // performance check for query
     if (empty($query)) {
         return;
     }
     // Support `route: '@self'` syntax
     if ($route === '@self') {
         $route = $page . route();
         $this->config->set('plugins.simplesearch.route', $route);
     }
     // performance check for route
     if (!($route && $route == $uri->path())) {
         return;
     }
     // Explode query into multiple strings
     $this->query = explode(',', $query);
     /** @var Taxonomy $taxonomy_map */
     $taxonomy_map = $this->grav['taxonomy'];
     $taxonomies = [];
     $find_taxonomy = [];
     $filters = (array) $this->config->get('plugins.simplesearch.filters');
     $operator = $this->config->get('plugins.simplesearch.filter_combinator', 'and');
     $new_approach = false;
     if (!$filters || $query === false || count($filters) == 1 && !reset($filters)) {
         /** @var \Grav\Common\Page\Pages $pages */
         $pages = $this->grav['pages'];
         $this->collection = $pages->all();
     } else {
         foreach ($filters as $key => $filter) {
             // flatten item if it's wrapped in an array
             if (is_int($key)) {
                 if (is_array($filter)) {
                     $key = key($filter);
                     $filter = $filter[$key];
                 } else {
                     $key = $filter;
                 }
             }
             // see if the filter uses the new 'items-type' syntax
             if ($key === '@self' || $key === 'self@') {
                 $new_approach = true;
             } elseif ($key === '@taxonomy' || $key === 'taxonomy@') {
                 $taxonomies = $filter === false ? false : array_merge($taxonomies, (array) $filter);
             } else {
                 $find_taxonomy[$key] = $filter;
             }
         }
         if ($new_approach) {
             $params = $page->header()->content;
             $params['query'] = $this->config->get('plugins.simplesearch.query');
             $this->collection = $page->collection($params, false);
         } else {
             $this->collection = new Collection();
             $this->collection->append($taxonomy_map->findTaxonomy($find_taxonomy, $operator)->toArray());
         }
     }
     $extras = [];
     if ($query) {
         foreach ($this->collection as $cpage) {
             foreach ($this->query as $query) {
                 $query = trim($query);
                 if ($this->notFound($query, $cpage, $taxonomies)) {
                     $this->collection->remove($cpage);
                     continue;
                 }
                 if ($cpage->modular()) {
                     $this->collection->remove($cpage);
                     $parent = $cpage->parent();
                     $extras[$parent->path()] = ['slug' => $parent->slug()];
                 }
             }
         }
     }
     if (!empty($extras)) {
         $this->collection->append($extras);
     }
     // use a configured sorting order if not already done
     if (!$new_approach) {
         $this->collection = $this->collection->order($this->config->get('plugins.simplesearch.order.by'), $this->config->get('plugins.simplesearch.order.dir'));
     }
     // if page doesn't have settings set, create a page
     if (!isset($page->header()->simplesearch)) {
         // create the search page
         $page = new Page();
         $page->init(new \SplFileInfo(__DIR__ . '/pages/simplesearch.md'));
         // override the template is set in the config
         $template_override = $this->config->get('plugins.simplesearch.template');
//.........这里部分代码省略.........
开发者ID:statrixbob,项目名称:gravblog,代码行数:101,代码来源:simplesearch.php

示例7: onPageInitialized

 /**
  * Create search result page.
  */
 public function onPageInitialized()
 {
     $page = new Page();
     $page->init(new \SplFileInfo(__DIR__ . '/pages/simplesearch.md'));
     // override the template is set in the config
     $template_override = $this->config->get('plugins.simplesearch.template');
     if ($template_override) {
         $page->template($template_override);
     }
     // allows us to redefine the page service without triggering RuntimeException: Cannot override frozen service
     // "page" issue
     unset($this->grav['page']);
     $this->grav['page'] = $page;
 }
开发者ID:hibbittsdesign,项目名称:cmpt-363-153-website,代码行数:17,代码来源:simplesearch.php

示例8: onPagesInitialized

 /**
  * Build search results.
  */
 public function onPagesInitialized()
 {
     /** @var Taxonomy $taxonomy_map */
     $taxonomy_map = $this->grav['taxonomy'];
     $filters = (array) $this->config->get('plugins.simplesearch.filters');
     $operator = $this->config->get('plugins.simplesearch.filter_combinator', 'and');
     $this->collection = new Collection();
     $this->collection->append($taxonomy_map->findTaxonomy($filters, $operator)->toArray());
     $extras = [];
     /** @var Page $page */
     foreach ($this->collection as $page) {
         foreach ($this->query as $query) {
             $query = trim($query);
             if (stripos($page->content(), $query) === false && stripos($page->title(), $query) === false) {
                 $this->collection->remove($page);
                 continue;
             }
             if ($page->modular()) {
                 $this->collection->remove($page);
                 $parent = $page->parent();
                 $extras[$parent->path()] = ['slug' => $parent->slug()];
             }
         }
     }
     if (!empty($extras)) {
         $this->collection->append($extras);
     }
     // create the search page
     $page = new Page();
     $page->init(new \SplFileInfo(__DIR__ . '/pages/simplesearch.md'));
     // override the template is set in the config
     $template_override = $this->config->get('plugins.simplesearch.template');
     if ($template_override) {
         $page->template($template_override);
     }
     // allows us to redefine the page service without triggering RuntimeException: Cannot override frozen service
     // "page" issue
     unset($this->grav['page']);
     $this->grav['page'] = $page;
 }
开发者ID:gabykode,项目名称:tf,代码行数:43,代码来源:simplesearch.php

示例9: 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;
 }
开发者ID:qbi,项目名称:datenknoten.me,代码行数:32,代码来源:Twig.php

示例10: preparePage

 /**
  * Prepare a page to be stored: update its folder, name, template, header and content
  *
  * @param \Grav\Common\Page\Page $page
  * @param bool                   $clean_header
  */
 protected function preparePage(\Grav\Common\Page\Page $page, $clean_header = false)
 {
     $input = $this->post;
     $order = max(0, (int) isset($input['order']) ? $input['order'] : $page->value('order'));
     $ordering = $order ? sprintf('%02d.', $order) : '';
     $slug = empty($input['folder']) ? $page->value('folder') : (string) $input['folder'];
     $page->folder($ordering . $slug);
     if (isset($input['type']) && !empty($input['type'])) {
         $type = (string) strtolower($input['type']);
         $name = preg_replace('|.*/|', '', $type) . '.md';
         $page->name($name);
         $page->template($type);
     }
     // Special case for Expert mode: build the raw, unset content
     if (isset($input['frontmatter']) && isset($input['content'])) {
         $page->raw("---\n" . (string) $input['frontmatter'] . "\n---\n" . (string) $input['content']);
         unset($input['content']);
     }
     if (isset($input['header'])) {
         $header = $input['header'];
         if ($clean_header) {
             $header = Utils::arrayFilterRecursive($header, function ($k, $v) {
                 return !(is_null($v) || $v === '');
             });
         }
         $page->header((object) $header);
     }
     // Fill content last because it also renders the output.
     if (isset($input['content'])) {
         $page->rawMarkdown((string) $input['content']);
     }
 }
开发者ID:spiridonovn,项目名称:grav-plugin-admin,代码行数:38,代码来源:controller.php


注:本文中的Grav\Common\Page\Page::template方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。