<p>So just as an information architecture kind of thing, you might want to have just one <code>_layout.twig</code> that <em>all</em> of your entry types <code>extends</code>, and just include various <code>{% block %}</code> tags in the right places for the templates to fill in.</p>

<p>That way, if you make major changes to the abstract pages (say, adding meta info, or changing JavaScript that's loaded site-wide, etc.) you don't have to make those changes in a number of places.</p>

<p>You can also leverage <a href="https://twig.symfony.com/doc/2.x/tags/include.html" rel="nofollow noreferrer">include</a> and <a href="https://twig.symfony.com/doc/2.x/tags/embed.html" rel="nofollow noreferrer">embed</a> and you'll likely end up with a more manageable template hierarchy in the end.</p>

<p>That said, the problem you're having is that it's hitting this code block:</p>

<p>```</p>

<pre><code>public function loadTemplate($name, $index = null)
{
    try
    {
        return parent::loadTemplate($name, $index);
    }
    catch (\Twig_Error $e)
    {
        if (craft()-&gt;config-&gt;get('suppressTemplateErrors'))
        {
            // Just log it and return an empty template
            craft()-&gt;errorHandler-&gt;logException($e);

            $twig = craft()-&gt;templates-&gt;getTwig('Twig_Loader_String');
            return $twig-&gt;loadTemplate('');
        }
        else
        {
            throw $e;
        }
    }
}
</code></pre>

<p>```</p>

<p>So while it normally would throw an exception, which Twig handles and then moves on to try the next template in the array you've passed it, with <code>suppressTemplateErrors =&gt; true</code> it just immediately returns an empty template.</p>

<p>You can file a bug report if you like, because this does appear to short-circuit the normal Twig fallback mechanism for template rendering, but I'd honestly re-examine how you're doing things. Depending on suppressing template errors for the site to work feels wrong.</p>

CC BY-SA 3.0
2017-12-26T17:03:22.133Z
we actually are extending a _layout.twig file, with a {% block %} and everything :) We just use this method for when we have entries that are slightly different from the others, to load a slightly different template. We do this is stead of creating new singles for everything. Seemed like a neat way to keep the cms clean. Unless you know a better method? For example: In the cms, the contact page has the exact same fields as the other pages, but in the front it needs to output a contact form as well, so we create a template: pages/contact.twig .
manomoul
CC BY-SA 3.0
2017-12-27T14:39:47.523Z
I am with @khalwat, you probably don't want to do this on an extends level but your approach is fine for includes and embeds... I use it all the time.
AbbeyDesign
CC BY-SA 3.0
2017-12-26T16:56:09.163Z
2017-12-26T16:56:09.163Z
andrew.welch
<p>If I set </p>

<pre><code>'suppressTemplateErrors' =&gt; true 
</code></pre>

<p>in the config/general.php</p>

<p>This (templates/_pages/_entry.twig): </p>

<pre><code>{% extends [
'_pages/'~entry.slug|default,
"_pages/" ~ entry.type|default,
"_pages/default"
] %}
</code></pre>

<p>Gets me a blank page, since apparently it is seen as a mistake, and the execution of the twig template is stopped. However, when suppressTemplateErrors is set to false, there is no problem. 
the code is supposed to search for a template with the name of an entry slug, if that doesn't exist look for one with the name of the type, and if that doesn't exist, load the default template. </p>

<p><strong>Logs (web.log):</strong></p>

<pre><code>2017-12-26 15:54:02 [::1][1][-][error][craft\web\twig\TemplateLoaderException] craft\web\twig\TemplateLoaderException: Coud not find template “_pages/about” . in /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/twig/TemplateLoader.php:125
Stack trace:
#0 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/twig/TemplateLoader.php(76): craft\web\twig\TemplateLoader-&gt;_resolveTemplate('_pages/about')
#1 /Users/username/Code/mywebsite/vendor/twig/twig/lib/Twig/Environment.php(270): craft\web\twig\TemplateLoader-&gt;getCacheKey('_pages/about')
#2 /Users/username/Code/mywebsite/vendor/twig/twig/lib/Twig/Environment.php(350): Twig_Environment-&gt;getTemplateClass('_pages/about')
#3 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/twig/Environment.php(30): Twig_Environment-&gt;loadTemplate('_pages/about', NULL)
#4 /Users/username/Code/mywebsite/vendor/twig/twig/lib/Twig/Environment.php(478): craft\web\twig\Environment-&gt;loadTemplate('_pages/about')
#5 /Users/username/Code/mywebsite/vendor/twig/twig/lib/Twig/Template.php(318): Twig_Environment-&gt;resolveTemplate(Array)
#6 /Users/username/Code/mywebsite/storage/runtime/compiled_templates/74/74f99748b2c43647e59f94561c58e670362eb7351e4ca94b81c3fcb1a4265158.php(10): Twig_Template-&gt;loadTemplate(Array, '_pages/_entry', 2)
#7 /Users/username/Code/mywebsite/vendor/twig/twig/lib/Twig/Template.php(99): __TwigTemplate_49b39b86eb9a0dbc650dce81e0d17fe48175bd75d54e21236890fb8d13a20492-&gt;doGetParent(Array)
#8 /Users/username/Code/mywebsite/storage/runtime/compiled_templates/74/74f99748b2c43647e59f94561c58e670362eb7351e4ca94b81c3fcb1a4265158.php(16): Twig_Template-&gt;getParent(Array)
#9 /Users/username/Code/mywebsite/vendor/twig/twig/lib/Twig/Template.php(389): __TwigTemplate_49b39b86eb9a0dbc650dce81e0d17fe48175bd75d54e21236890fb8d13a20492-&gt;doDisplay(Array, Array)
#10 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/twig/Template.php(51): Twig_Template-&gt;displayWithErrorHandling(Array, Array)
#11 /Users/username/Code/mywebsite/vendor/twig/twig/lib/Twig/Template.php(366): craft\web\twig\Template-&gt;displayWithErrorHandling(Array, Array)
#12 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/twig/Template.php(32): Twig_Template-&gt;display(Array, Array)
#13 /Users/username/Code/mywebsite/vendor/twig/twig/lib/Twig/Template.php(374): craft\web\twig\Template-&gt;display(Array)
#14 /Users/username/Code/mywebsite/vendor/twig/twig/lib/Twig/Environment.php(289): Twig_Template-&gt;render(Array)
#15 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/View.php(292): Twig_Environment-&gt;render('_pages/_entry', Array)
#16 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/View.php(340): craft\web\View-&gt;renderTemplate('_pages/_entry', Array)
#17 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/Controller.php(121): craft\web\View-&gt;renderPageTemplate('_pages/_entry', Array)
#18 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/controllers/TemplatesController.php(79): craft\web\Controller-&gt;renderTemplate('_pages/_entry', Array)
#19 [internal function]: craft\controllers\TemplatesController-&gt;actionRender('_pages/_entry', Array)
#20 /Users/username/Code/mywebsite/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#21 /Users/username/Code/mywebsite/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction-&gt;runWithParams(Array)
#22 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/Controller.php(80): yii\base\Controller-&gt;runAction('render', Array)
#23 /Users/username/Code/mywebsite/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller-&gt;runAction('render', Array)
#24 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/Application.php(242): yii\base\Module-&gt;runAction('templates/rende...', Array)
#25 /Users/username/Code/mywebsite/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application-&gt;runAction('templates/rende...', Array)
#26 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/Application.php(207): yii\web\Application-&gt;handleRequest(Object(craft\web\Request))
#27 /Users/username/Code/mywebsite/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application-&gt;handleRequest(Object(craft\web\Request))
#28 /Users/username/Code/mywebsite/www/index.php(35): yii\base\Application-&gt;run()
#29 {main}
</code></pre>

CC BY-SA 3.0
2017-12-26T15:41:44.597Z
What does the ``craft.log`` say when ``suppressTemplateErrors`` is true?
RitterKnight
CC BY-SA 3.0
2017-12-26T16:42:50.250Z
2017-12-26 15:54:02 [::1][1][-][error][craft\web\twig\TemplateLoaderException] craft\web\twig\TemplateLoaderException: Coud not find template “_pages/about” . in /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/twig/TemplateLoader.php:125
manomoul
CC BY-SA 3.0
2017-12-27T14:35:15.720Z
Why do you need suppressTemplateErrors set to true? What is the purpose of adding the "|default" part to the first two template calls?
AbbeyDesign
<templating>
template extend not working if suppressTemplateError is set to true
# template extend not working if suppressTemplateError is set to true

(Asked by: username_0 on 2017-12-26)

If I set 
'suppressTemplateErrors' => true 

in the config/general.php
This (templates/_pages/_entry.twig): 
{% extends [
'_pages/'~entry.slug|default,
"_pages/" ~ entry.type|default,
"_pages/default"
] %}

Gets me a blank page, since apparently it is seen as a mistake, and the execution of the twig template is stopped. However, when suppressTemplateErrors is set to false, there is no problem. 
the code is supposed to search for a template with the name of an entry slug, if that doesn't exist look for one with the name of the type, and if that doesn't exist, load the default template. 
Logs (web.log):
2017-12-26 15:54:02 [::1][1][-][error][craft\web\twig\TemplateLoaderException] craft\web\twig\TemplateLoaderException: Coud not find template “_pages/about” . in /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/twig/TemplateLoader.php:125
Stack trace:
#0 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/twig/TemplateLoader.php(76): craft\web\twig\TemplateLoader->_resolveTemplate('_pages/about')
#1 /Users/username/Code/mywebsite/vendor/twig/twig/lib/Twig/Environment.php(270): craft\web\twig\TemplateLoader->getCacheKey('_pages/about')
#2 /Users/username/Code/mywebsite/vendor/twig/twig/lib/Twig/Environment.php(350): Twig_Environment->getTemplateClass('_pages/about')
#3 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/twig/Environment.php(30): Twig_Environment->loadTemplate('_pages/about', NULL)
#4 /Users/username/Code/mywebsite/vendor/twig/twig/lib/Twig/Environment.php(478): craft\web\twig\Environment->loadTemplate('_pages/about')
#5 /Users/username/Code/mywebsite/vendor/twig/twig/lib/Twig/Template.php(318): Twig_Environment->resolveTemplate(Array)
#6 /Users/username/Code/mywebsite/storage/runtime/compiled_templates/74/74f99748b2c43647e59f94561c58e670362eb7351e4ca94b81c3fcb1a4265158.php(10): Twig_Template->loadTemplate(Array, '_pages/_entry', 2)
#7 /Users/username/Code/mywebsite/vendor/twig/twig/lib/Twig/Template.php(99): __TwigTemplate_49b39b86eb9a0dbc650dce81e0d17fe48175bd75d54e21236890fb8d13a20492->doGetParent(Array)
#8 /Users/username/Code/mywebsite/storage/runtime/compiled_templates/74/74f99748b2c43647e59f94561c58e670362eb7351e4ca94b81c3fcb1a4265158.php(16): Twig_Template->getParent(Array)
#9 /Users/username/Code/mywebsite/vendor/twig/twig/lib/Twig/Template.php(389): __TwigTemplate_49b39b86eb9a0dbc650dce81e0d17fe48175bd75d54e21236890fb8d13a20492->doDisplay(Array, Array)
#10 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/twig/Template.php(51): Twig_Template->displayWithErrorHandling(Array, Array)
#11 /Users/username/Code/mywebsite/vendor/twig/twig/lib/Twig/Template.php(366): craft\web\twig\Template->displayWithErrorHandling(Array, Array)
#12 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/twig/Template.php(32): Twig_Template->display(Array, Array)
#13 /Users/username/Code/mywebsite/vendor/twig/twig/lib/Twig/Template.php(374): craft\web\twig\Template->display(Array)
#14 /Users/username/Code/mywebsite/vendor/twig/twig/lib/Twig/Environment.php(289): Twig_Template->render(Array)
#15 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/View.php(292): Twig_Environment->render('_pages/_entry', Array)
#16 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/View.php(340): craft\web\View->renderTemplate('_pages/_entry', Array)
#17 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/Controller.php(121): craft\web\View->renderPageTemplate('_pages/_entry', Array)
#18 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/controllers/TemplatesController.php(79): craft\web\Controller->renderTemplate('_pages/_entry', Array)
#19 [internal function]: craft\controllers\TemplatesController->actionRender('_pages/_entry', Array)
#20 /Users/username/Code/mywebsite/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#21 /Users/username/Code/mywebsite/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#22 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/Controller.php(80): yii\base\Controller->runAction('render', Array)
#23 /Users/username/Code/mywebsite/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('render', Array)
#24 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/Application.php(242): yii\base\Module->runAction('templates/rende...', Array)
#25 /Users/username/Code/mywebsite/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('templates/rende...', Array)
#26 /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/Application.php(207): yii\web\Application->handleRequest(Object(craft\web\Request))
#27 /Users/username/Code/mywebsite/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#28 /Users/username/Code/mywebsite/www/index.php(35): yii\base\Application->run()
#29 {main}

**Tags:** templating
> **Comments:**
> **username_1**: What does the ``craft.log`` say when ``suppressTemplateErrors`` is true?  
> **username_0**: 2017-12-26 15:54:02 [::1][1][-][error][craft\web\twig\TemplateLoaderException] craft\web\twig\TemplateLoaderException: Coud not find template “_pages/about” . in /Users/username/Code/mywebsite/vendor/craftcms/cms/src/web/twig/TemplateLoader.php:125  
> **username_2**: Why do you need suppressTemplateErrors set to true? What is the purpose of adding the "|default" part to the first two template calls?  

---

## 1 answers

### Answer by username_3 on 2017-12-26. Score: 1

So just as an information architecture kind of thing, you might want to have just one _layout.twig that all of your entry types extends, and just include various {% block %} tags in the right places for the templates to fill in.
That way, if you make major changes to the abstract pages (say, adding meta info, or changing JavaScript that's loaded site-wide, etc.) you don't have to make those changes in a number of places.
You can also leverage include and embed and you'll likely end up with a more manageable template hierarchy in the end.
That said, the problem you're having is that it's hitting this code block:
```
public function loadTemplate($name, $index = null)
{
    try
    {
        return parent::loadTemplate($name, $index);
    }
    catch (\Twig_Error $e)
    {
        if (craft()->config->get('suppressTemplateErrors'))
        {
            // Just log it and return an empty template
            craft()->errorHandler->logException($e);

            $twig = craft()->templates->getTwig('Twig_Loader_String');
            return $twig->loadTemplate('');
        }
        else
        {
            throw $e;
        }
    }
}

```
So while it normally would throw an exception, which Twig handles and then moves on to try the next template in the array you've passed it, with suppressTemplateErrors => true it just immediately returns an empty template.
You can file a bug report if you like, because this does appear to short-circuit the normal Twig fallback mechanism for template rendering, but I'd honestly re-examine how you're doing things. Depending on suppressing template errors for the site to work feels wrong.

> **Comments:**
> **username_0**: we actually are extending a _layout.twig file, with a {% block %} and everything :) We just use this method for when we have entries that are slightly different from the others, to load a slightly different template. We do this is stead of creating new singles for everything. Seemed like a neat way to keep the cms clean. Unless you know a better method? For example: In the cms, the contact page has the exact same fields as the other pages, but in the front it needs to output a contact form as well, so we create a template: pages/contact.twig .  
> **username_2**: I am with @khalwat, you probably don't want to do this on an extends level but your approach is fine for includes and embeds... I use it all the time.  

---

