Skip to content

Commit

Permalink
Accessing page with unsupported file extension (jpg, pdf, xsl) will u…
Browse files Browse the repository at this point in the history
…se wrong mime type [#3031]
  • Loading branch information
mahagr committed Oct 8, 2020
1 parent 3821ae4 commit 1eb85b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v1.7.0-rc.18
## mm/dd/2020

1. [](#bugfix)
* Accessing page with unsupported file extension (jpg, pdf, xsl) will use wrong mime type [#3031](https://github.com/getgrav/grav/issues/3031)

# v1.7.0-rc.17
## 10/07/2020

Expand Down
8 changes: 7 additions & 1 deletion system/src/Grav/Common/Twig/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,9 @@ public function processSite($format = null, array $vars = [])
{
// set the page now its been processed
$this->grav->fireEvent('onTwigSiteVariables');
/** @var Pages $pages */
$pages = $this->grav['pages'];
/** @var PageInterface $page */
$page = $this->grav['page'];
$content = $page->content();

Expand All @@ -395,6 +397,7 @@ public function processSite($format = null, array $vars = [])

// Get Twig template layout
$template = $this->getPageTwigTemplate($page, $format);
$page->templateFormat($format);

try {
$output = $this->twig->render($template, $vars + $twig_vars);
Expand Down Expand Up @@ -445,7 +448,7 @@ public function template($template)
* @param string|null $format
* @return string
*/
public function getPageTwigTemplate($page, $format = null)
public function getPageTwigTemplate($page, &$format = null)
{
$template = $page->template();
$extension = $format ?: $page->templateFormat();
Expand All @@ -463,14 +466,17 @@ public function getPageTwigTemplate($page, $format = null)
// Try with template + html.twig
if ($twig_extension !== TEMPLATE_EXT && $loader->exists($template . TEMPLATE_EXT)) {
$page_template = $template . TEMPLATE_EXT;
$format = 'html';
// Try with default and original extension
} elseif ($loader->exists('default' . $twig_extension)) {
$page_template = 'default' . $twig_extension;
// Else try default + default extension
} elseif (!$page->isModule() && $loader->exists('default' . TEMPLATE_EXT)) {
$page_template = 'default' . TEMPLATE_EXT;
$format = 'html';
} else {
$page_template = 'modular/default' . TEMPLATE_EXT;
$format = 'html';
}
}
}
Expand Down

0 comments on commit 1eb85b3

Please sign in to comment.