For example the template just outputs JSON, which breaks when Craft's devMode logging is added.
2 Answers
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" %}
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.
-
Thanks Brad - good to know. Setting the Content-Type was enough in the end, at least for this particular scenario. Commented Mar 6, 2015 at 12:15
-
I putt this on github if people are feeling lazy: github.com/crswll/silence Commented Mar 21, 2015 at 1:29
{% header "Content-Type: application/json" %}