<p>If you have <a href="https://craftcms.com/docs/config-settings#devMode" rel="nofollow">devMode</a> enabled, then you have access to Twig's <code>dump</code> method that lets you inspect variables.</p>

<pre><code>{{ dump(article_id) }}
</code></pre>

<p>Or, if you're feeling more adventurous, there is a debugging library called <a href="https://raveren.github.io/kint/" rel="nofollow">Kint</a> that there is a Craft <a href="https://github.com/mildlygeeky/craft_kint" rel="nofollow">plugin</a> for to help debug templates.</p>

CC BY-SA 3.0
2016-03-03T01:34:45.020Z
Dump is a very useful, but it still doesn't let me access the information when there's a Template Error ,which is my main issue. Suppressing, or writing to, the Template Error page is the main thing that I need
kai
CC BY-SA 3.0
2016-03-03T01:37:28.897Z
Oh... maybe I'm not following.  You want to still be able to write to the page (or a log file) even when there's a Twig error?
Brad Bell
CC BY-SA 3.0
2016-03-03T01:48:44.827Z
Yes, I want to be able to either write to the Twig Error page, a log file, the browser log, or similar. I just looked at Kint (which is pretty nice) and it looks like it displays the errors with `{{ render }}` style code. It occurs to me that if it displayed with the `{% render %}{% endrender %}` style, it could bypass this particular Template Error.

(sorry if that's not more clear!)
kai
CC BY-SA 3.0
2016-03-03T02:17:26.337Z
Hrm... I'm not sure it's possible do to what you're looking for then. When a Twig error occurs, an exception is thrown and the rest of the Twig template isn't processed, so there'd be no chance for you (or a plugin) to do anything else from Twig. The best you could do is have a plugin that listened for Yii's onError and onException events.
Brad Bell
CC BY-SA 3.0
2016-03-03T01:28:50.847Z
2016-03-03T01:28:50.847Z
Brad Bell
<p>I'm trying to get this code working</p>

<pre><code>{% if article_id is defined %}
    {% set entry = craft.entries.id(article_id).first() %}
{% endif %}
</code></pre>

<p>The code itself is unimportant, what's relevant is that I'm currently working outside of the context where I would rendering an article. This particular code happens to be broken, and I would like to fix it via inspecting <code>{{ article_id }}</code>. Except I can't, because:</p>

<pre><code>Template Error

A template that extends another one cannot have a body.

---

{% extends "_base" %}

{% if article_id is defined %}
    {% set entry = craft.entries.id(article_id).first() %}
    {{ article_id }}
{% endif %}
</code></pre>

<p>Now there's a variety of ways that I could solve this issue, but I'm wondering what's the best option. Ideally it would be something like <code>{{ craft.log(article_id) }}</code> - ie. a function would still produce the Template Error, but at also let me see the value / other information about <code>article_id</code> (either in the error window, or on the javascript console log).</p>

<p>How should I implement the logging behavior that I'm looking for?</p>

CC BY-SA 3.0
2016-03-03T01:50:52.250Z
For the record, I solved the issue with the code above before I even posted this question. It was just the example I had on hand
kai
<templating>
Log to console / error window?
# Log to console / error window?

(Asked by: username_0 on 2016-03-03)

I'm trying to get this code working
{% if article_id is defined %}
    {% set entry = craft.entries.id(article_id).first() %}
{% endif %}

The code itself is unimportant, what's relevant is that I'm currently working outside of the context where I would rendering an article. This particular code happens to be broken, and I would like to fix it via inspecting {{ article_id }}. Except I can't, because:
Template Error

A template that extends another one cannot have a body.

---

{% extends "_base" %}

{% if article_id is defined %}
    {% set entry = craft.entries.id(article_id).first() %}
    {{ article_id }}
{% endif %}

Now there's a variety of ways that I could solve this issue, but I'm wondering what's the best option. Ideally it would be something like {{ craft.log(article_id) }} - ie. a function would still produce the Template Error, but at also let me see the value / other information about article_id (either in the error window, or on the javascript console log).
How should I implement the logging behavior that I'm looking for?

**Tags:** templating
> **Comments:**
> **username_0**: For the record, I solved the issue with the code above before I even posted this question. It was just the example I had on hand  

---

## 1 answers

### Answer by username_1 on 2016-03-03. Score: 2

If you have devMode enabled, then you have access to Twig's dump method that lets you inspect variables.
{{ dump(article_id) }}

Or, if you're feeling more adventurous, there is a debugging library called Kint that there is a Craft plugin for to help debug templates.

> **Comments:**
> **username_0**: Dump is a very useful, but it still doesn't let me access the information when there's a Template Error ,which is my main issue. Suppressing, or writing to, the Template Error page is the main thing that I need  
> **username_1**: Oh... maybe I'm not following.  You want to still be able to write to the page (or a log file) even when there's a Twig error?  
> **username_0**: Yes, I want to be able to either write to the Twig Error page, a log file, the browser log, or similar. I just looked at Kint (which is pretty nice) and it looks like it displays the errors with `{{ render }}` style code. It occurs to me that if it displayed with the `{% render %}{% endrender %}` style, it could bypass this particular Template Error.  (sorry if that's not more clear!)  
> **username_1**: Hrm... I'm not sure it's possible do to what you're looking for then. When a Twig error occurs, an exception is thrown and the rest of the Twig template isn't processed, so there'd be no chance for you (or a plugin) to do anything else from Twig. The best you could do is have a plugin that listened for Yii's onError and onException events.  

---

