diff --git a/CHANGELOG.md b/CHANGELOG.md index eb712ce7a..3dd656954 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ 1. [](#improved) * Allow custom Flex form views * Cleaned up and sorted the Service `idMap` + * Allow request headers `Content-Type` to set the template type [form#221](https://github.com/getgrav/grav-plugin-form/issues/221) # v1.6.0-beta.5 ## 11/05/2018 diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index b39009a13..0ca5e48ef 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -1288,7 +1288,10 @@ class Page implements PageInterface } if (empty($this->template_format)) { - $this->template_format = Grav::instance()['uri']->extension('html'); + $content_type = Grav::instance()['uri']->getContentType(true); + $fallback_type = Utils::getExtensionByMime($content_type); + $default = is_null($content_type) ? Grav::instance()['uri']->extension('html') : $fallback_type; + $this->template_format = $default; } return $this->template_format; diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 9480e4948..274dd963a 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -1307,7 +1307,7 @@ class Uri * @param bool $short * @return null|string */ - private function getContentType($short = true) + public function getContentType($short = true) { if (isset($_SERVER['CONTENT_TYPE'])) { $content_type = $_SERVER['CONTENT_TYPE'];