Learn

The Debug Variable

As of v1.7.6, Statamic now creates a {{ _debug }} variable on every page. This variable is a named-list, which currently contains the following information:

  • layout is the layout that was used to render the current page
  • template is the template that was used to render the current page
  • environment is the environment that was matched and is being used
  • theme is the theme being used
  • statamic_version (renamed from version in v1.7.9) is the version of Statamic being used by the current site
  • php_version (added in v1.7.9) is the current PHP version being used by the site

Using _debug

A useful idea for displaying debug information is to dump it into an HTML comment at the top of your pages when in a development environment. First, you’ll want to set up a development environment. For this example, let’s assume that our environment matches a dev environment.

Next, at the top of your default layout file, just inside of your HTML tag, put the following:

<html>
{{ if is_dev }}
<!--

debug information
---------------------------------------------------------
{{ _debug|dump }}
---------------------------------------------------------

-->
{{ endif }}

Now refresh your page and view the source. (You can also view the source of this page, we’ve added the _debug stuff to it just for you to look at.)

You can also access any of the individual _debug variables with the colon-syntax, for example, the current template can be displayed with {{ _debug:template }}.

This article was last updated on September 13th, 2016. Find an error? Please let us know!