Skip to content

Commit

Permalink
Added default templates in Grav itself
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Sep 18, 2020
1 parent 20c4468 commit 9880ce9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# v1.7.0-rc.17
## mm/dd/2020

1. [](#improved)
* Fall back through various templates scenarios if they don't exist in theme to avoid unhelpful error.
* Added default templates for `external.html.twig`, `default.html.twig`, and `modular.html.twig`
1. [](#bugfix)
* Fixed `Security::sanitizeSVG()` creating an empty file if SVG file cannot be parsed
* Fixed infinite loop in blueprints with `extend@` to a parent stream
Expand Down
27 changes: 22 additions & 5 deletions system/src/Grav/Common/Twig/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,14 +445,31 @@ public function getPageTwigTemplate($page, $format = null)
$twig_extension = $extension ? '.'. $extension .TWIG_EXT : TEMPLATE_EXT;
$template_file = $this->template($page->template() . $twig_extension);

$page_template = null;

$loader = $this->twig->getLoader();
if ($loader instanceof ExistsLoaderInterface && $loader->exists($template_file)) {
return $template_file;
if ($loader instanceof ExistsLoaderInterface ) {

if ($loader->exists($template_file)) {
$page_template = $template_file;
} else {
// Try with template + html.twig
if ($twig_extension !== TEMPLATE_EXT && $loader->exists($template . TEMPLATE_EXT)) {
$page_template = $template . TEMPLATE_EXT;
// Try with default and original extension
} elseif ($loader->exists('default' . $twig_extension)) {
$page_template = 'default' . $twig_extension;
// Else try default + default extension
} elseif (!$page->modular() && $loader->exists('default' . TEMPLATE_EXT)) {
$page_template = 'default' . TEMPLATE_EXT;
} else {
$page_template = 'modular/default' . TEMPLATE_EXT;
}
}
}

// Default to HTML
$page->templateFormat('html');
return $template . TEMPLATE_EXT;
return $page_template;

}

/**
Expand Down
4 changes: 4 additions & 0 deletions system/templates/default.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{# Default output if no theme #}
<h3 style="color:red">ERROR: <code>{{ page.template() ~'.'~ page.templateFormat() ~".twig" }}</code> template not found for page: <code>{{ page.route() }}</code></h3>
<h1>{{ page.title() }}</h1>
{{ page.content()|raw }}
1 change: 1 addition & 0 deletions system/templates/external.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{# Default external template #}
4 changes: 4 additions & 0 deletions system/templates/modular/default.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{# Default output if no theme #}
<h3 style="color:red">ERROR: <code>{{ page.template() ~'.'~ page.templateFormat() ~".twig" }}</code> template not found for page: <code>{{ page.route() }}</code></h3>
<h1>{{ page.title() }}</h1>
{{ page.content()|raw }}

0 comments on commit 9880ce9

Please sign in to comment.