Set template type based on request headers content-type if set

This commit is contained in:
Andy Miller
2018-11-09 17:10:03 -07:00
parent 63005a8280
commit 005f626b88
3 changed files with 6 additions and 2 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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'];