From 1401102396122ce49d30e67a91c1f5596f5ba166 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 4 Aug 2015 09:40:59 -0600 Subject: [PATCH] more extensive extension() method --- system/src/Grav/Common/Page/Page.php | 35 ++++++++++++++-------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 67560a0c7..cdcfbb436 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -605,22 +605,6 @@ class Page return null; } - /** - * Get page extension - * - * @param $var - * - * @return mixed - */ - public function extension($var = null) - { - if ($var !== null) { - $this->extension = $var; - } - - return $this->extension; - } - /** * Save page if there's a file assigned to it. * @param bool $reorder Internal use. @@ -853,11 +837,28 @@ class Page $this->template = $var; } if (empty($this->template)) { - $this->template = ($this->modular() ? 'modular/' : '') . str_replace($this->extension, '', $this->name()); + $this->template = ($this->modular() ? 'modular/' : '') . str_replace($this->extension(), '', $this->name()); } return $this->template; } + /** + * Gets and sets the extension field. + * + * @param null $var + * @return null|string + */ + public function extension($var = null) + { + if ($var !== null) { + $this->extension = $var; + } + if (empty($this->extension)) { + $this->extension = '.' . pathinfo($this->name(), PATHINFO_EXTENSION); + } + return $this->extension; + } + /** * Gets and sets the expires field. If not set will return the default *