Added default templates in Grav itself

This commit is contained in:
Andy Miller
2020-09-18 12:49:10 -06:00
parent 20c4468edd
commit 9880ce977a
5 changed files with 34 additions and 5 deletions

View File

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

View File

@@ -445,14 +445,31 @@ class Twig
$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;
}
/**

View File

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

View File

@@ -0,0 +1 @@
{# Default external template #}

View File

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