diff --git a/CHANGELOG.md b/CHANGELOG.md index 631e7f551..82cde6e37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## xx/xx/2017 1. [](#improved) + * Added various `ancestor` helper methods in Page and Pages classes [#1362](https://github.com/getgrav/grav/pull/1362) * Added `isajaxrequest()` Twig function [#1400](https://github.com/getgrav/grav/issues/1400) * Added ability to inline CSS and JS code via Asset manager [#1377](https://github.com/getgrav/grav/pull/1377) * Add query string in lighttpd default config [#1393](https://github.com/getgrav/grav/issues/1393) diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 9d5fd0ec1..c7ca2dd7a 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -303,7 +303,7 @@ class Pages { if (!is_null($path)) { - $page = $this->getPage($route); + $page = $this->dispatch($route, true); if ($page->path() == $path) { return $page; @@ -327,7 +327,7 @@ class Pages { if (!is_null($field)) { - $page = $this->getPage($route); + $page = $this->dispatch($route, true); $ancestorField = $page->parent()->value('header.' . $field); @@ -366,7 +366,12 @@ class Pages */ public function dispatch($route, $all = false, $redirect = true) { - $page = $this->getPage($route); + // Fetch page if there's a defined route to it. + $page = isset($this->routes[$route]) ? $this->get($this->routes[$route]) : null; + // Try without trailing slash + if (!$page && Utils::endsWith($route, '/')) { + $page = isset($this->routes[rtrim($route, '/')]) ? $this->get($this->routes[rtrim($route, '/')]) : null; + } // Are we in the admin? this is important! $not_admin = !isset($this->grav['admin']); @@ -434,22 +439,6 @@ class Pages return $page; } - /** - * Retrieve page instance based on the route - * - * @return Page - */ - protected function getPage($route) { - // Fetch page if there's a defined route to it. - $page = isset($this->routes[$route]) ? $this->get($this->routes[$route]) : null; - // Try without trailing slash - if (!$page && Utils::endsWith($route, '/')) { - $page = isset($this->routes[rtrim($route, '/')]) ? $this->get($this->routes[rtrim($route, '/')]) : null; - } - - return $page; - } - /** * Get root page. *