<p>You can't disable the debugging output using Twig/templates.</p>

<p>However, Craft will only render the debug data if your document' Content-type header is either "text/html" or "application/xhtml+xml" (<a href="https://craftcms.stackexchange.com/a/2294/1098">source</a>).</p>

<p>This means that if you're outputting JSON, you can set the template's Content-type to "application/json" (using Craft's <a href="http://buildwithcraft.com/docs/templating/tags#header" rel="nofollow noreferrer">header tag</a>), preventing Craft from dumping the debug data to the response:</p>

<pre><code>{% header "Content-Type: application/json" %}
</code></pre>

CC BY-SA 3.0
2015-03-06T12:27:33.140Z
2015-03-06T12:27:33.140Z
2017-04-13T12:51:00.303Z
Mats Mikkel Rummelhoff
<p>You can create a simple plugin with an <code>init()</code> method like so:</p>

<pre><code>public function init()
{
    craft()-&gt;log-&gt;removeRoute('WebLogRoute');
    craft()-&gt;log-&gt;removeRoute('ProfileLogRoute');
}
</code></pre>

<p>That will prevent the extra logging and profiling information to be output in the browser's console when devMode is enabled.</p>

CC BY-SA 3.0
2015-03-06T12:15:55.770Z
Thanks Brad - good to know. Setting the Content-Type was enough in the end, at least for this particular scenario.
Russ Back
CC BY-SA 3.0
2015-03-21T01:29:15.603Z
I putt this on github if people are feeling lazy: https://github.com/crswll/silence
Bill Criswell
CC BY-SA 3.0
2015-03-05T16:31:41.540Z
2015-03-05T16:31:41.540Z
Brad Bell
<p>For example the template just outputs JSON, which breaks when Craft's devMode logging is added.</p>

CC BY-SA 3.0
2015-03-05T16:16:40.367Z
I'm not aware of any way to disable the debugging output from the template, but if you use the header tag to explicitly set the document's content type to JSON, Craft wont output the debug data:

```{% header "Content-Type: application/json" %}```
Mats Mikkel Rummelhoff
CC BY-SA 3.0
2015-03-06T12:15:31.853Z
Thanks Mats - worked fine. Do you want to create an answer so I can mark it as accepted?
Russ Back
CC BY-SA 3.0
2015-03-06T12:28:21.470Z
That's great – I added an answer, thanks for following up.
Mats Mikkel Rummelhoff
<templating><javascript><devmode>
Is it possible to disable dev output in a template when devMode is true?
# Is it possible to disable dev output in a template when devMode is true?

(Asked by: username_0 on 2015-03-05)

For example the template just outputs JSON, which breaks when Craft's devMode logging is added.

**Tags:** templating, javascript, devmode
> **Comments:**
> **username_1**: I'm not aware of any way to disable the debugging output from the template, but if you use the header tag to explicitly set the document's content type to JSON, Craft wont output the debug data:  ```{% header "Content-Type: application/json" %}```  
> **username_0**: Thanks Mats - worked fine. Do you want to create an answer so I can mark it as accepted?  
> **username_1**: That's great – I added an answer, thanks for following up.  

---

## 2 answers

### Answer by username_1 on 2015-03-06. Score: 4 | Accepted answer

You can't disable the debugging output using Twig/templates.
However, Craft will only render the debug data if your document' Content-type header is either "text/html" or "application/xhtml+xml" (source).
This means that if you're outputting JSON, you can set the template's Content-type to "application/json" (using Craft's header tag), preventing Craft from dumping the debug data to the response:
{% header "Content-Type: application/json" %}


---

### Answer by username_2 on 2015-03-05. Score: 7

You can create a simple plugin with an init() method like so:
public function init()
{
    craft()->log->removeRoute('WebLogRoute');
    craft()->log->removeRoute('ProfileLogRoute');
}

That will prevent the extra logging and profiling information to be output in the browser's console when devMode is enabled.

> **Comments:**
> **username_0**: Thanks Brad - good to know. Setting the Content-Type was enough in the end, at least for this particular scenario.  
> **username_3**: I putt this on github if people are feeling lazy: https://github.com/crswll/silence  

---

