From 9a2dd4f07820569d3e8445dd41d90175d0db54d0 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Tue, 6 Dec 2016 20:52:27 +0100 Subject: [PATCH] Mark Twig variables rewrite_url and is_front_page as deprecated --- content-sample/index.md | 2 -- lib/Pico.php | 3 --- plugins/00-PicoDeprecated.php | 13 ++++++++++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/content-sample/index.md b/content-sample/index.md index 98cef99..d8d2f97 100644 --- a/content-sample/index.md +++ b/content-sample/index.md @@ -183,7 +183,6 @@ to use in your theme. Please note that paths (e.g. `{{ base_dir }}`) and URLs is enabled or not * `{{ theme_dir }}` - The path to the currently active theme * `{{ theme_url }}` - The URL to the currently active theme -* `{{ rewrite_url }}` - A boolean flag indicating enabled/disabled URL rewriting * `{{ site_title }}` - Shortcut to the site title (see `config/config.php`) * `{{ meta }}` - Contains the meta values from the current page * `{{ meta.title }}` @@ -213,7 +212,6 @@ to use in your theme. Please note that paths (e.g. `{{ base_dir }}`) and URLs * `{{ prev_page }}` - The data of the previous page (relative to `current_page`) * `{{ current_page }}` - The data of the current page * `{{ next_page }}` - The data of the next page (relative to `current_page`) -* `{{ is_front_page }}` - A boolean flag for the front page Pages can be used like the following: diff --git a/lib/Pico.php b/lib/Pico.php index 3d0b7dc..85388b1 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -1518,14 +1518,12 @@ class Pico return $this->twigVariables; } - $frontPage = $this->getConfig('content_dir') . 'index' . $this->getConfig('content_ext'); return array( 'config' => $this->getConfig(), 'base_dir' => rtrim($this->getRootDir(), '/'), 'base_url' => rtrim($this->getBaseUrl(), '/'), 'theme_dir' => $this->getThemesDir() . $this->getConfig('theme'), 'theme_url' => $this->getBaseThemeUrl() . $this->getConfig('theme'), - 'rewrite_url' => $this->isUrlRewritingEnabled(), 'site_title' => $this->getConfig('site_title'), 'meta' => $this->meta, 'content' => $this->content, @@ -1533,7 +1531,6 @@ class Pico 'prev_page' => $this->previousPage, 'current_page' => $this->currentPage, 'next_page' => $this->nextPage, - 'is_front_page' => ($this->requestFile === $frontPage), 'version' => static::VERSION ); } diff --git a/plugins/00-PicoDeprecated.php b/plugins/00-PicoDeprecated.php index 228212d..2d4a333 100644 --- a/plugins/00-PicoDeprecated.php +++ b/plugins/00-PicoDeprecated.php @@ -392,7 +392,8 @@ class PicoDeprecated extends AbstractPicoPlugin } /** - * Triggers the deprecated event before_render($twigVariables, $twig, $templateName) + * Adds the deprecated variables rewrite_url and is_front_page, triggers + * the deprecated event before_render($twigVariables, $twig, $templateName) * * Please note that the `before_render()` event gets `$templateName` passed * without its file extension. The file extension is later added again. @@ -401,6 +402,16 @@ class PicoDeprecated extends AbstractPicoPlugin */ public function onPageRendering(Twig_Environment &$twig, array &$twigVariables, &$templateName) { + // rewrite_url and is_front_page are deprecated since Pico 1.1 + if (!isset($twigVariables['rewrite_url'])) { + $twigVariables['rewrite_url'] = $this->isUrlRewritingEnabled(); + } + + if (!isset($twigVariables['is_front_page'])) { + $frontPage = $this->getConfig('content_dir') . 'index' . $this->getConfig('content_ext'); + $twigVariables['is_front_page'] = ($this->getRequestFile() === $frontPage); + } + // template name contains file extension since Pico 1.0 $fileExtension = ''; if (($fileExtensionPos = strrpos($templateName, '.')) !== false) {