{debug}

Shows values as a collapsible tree in the page, for a local request only, while rendering goes on.

Debugging and errors Single tags

Syntax

{debug}
{debug $value, $other}
{debug label=$value}

Parameters

value
Any number of items. A $name shows that field or array as it is - a missing one is shown as missing, not an error; anything else is evaluated as an expression. label=expression gives the box a name of its own. Without items: every field visible where the tag stands.

Description

{debug $order} writes the value where the tag stands, as a <details> box with its type and size in the summary - array(3), string(12), int - and nested arrays as a tree you can fold open. Unlike {dump} the request goes on: the rest of the page renders as usual, so several {debug} tags can follow a value through a loop.

The items are read raw, the way {attrs} reads them. A plain $name is looked up as a field or a page array, and when it does not exist the box says missing instead of ending the request under the strict syntax check. Any other item - $price * 2, count@items - is evaluated as an expression, and total=$price * 2 puts the label total on the box. Values whose name looks like a credential (passwords, tokens, keys) show redacted, as in the debug toolbar.

{debug} without items shows two boxes: fields here - the rows of the enclosing levels, innermost first - and application variables, every global that is not the engine's own.

Only a local request gets anything: the command line, or a loopback request with nothing forwarded. Every other visitor gets an empty string, and $padDiagnostics = FALSE switches it off for every web request. A page or a {cache} section holding a debug box is never stored in the page or fragment cache, so no later visitor is served what a local request was shown.

Examples

One value

The order array shown as a tree above the table; the page renders on below it.

Templateexamples/debug/1-one-value.src
{debug $order}
<table>
  {order}<tr><td>{$sku}</td><td>{$qty}</td></tr>{/order}
</table>

Inside a loop

Without items the tag shows the fields of the current row and the application variables.

Templateexamples/debug/2-inside-a-loop.src
{orders}
  <p>{$number}</p>
  {if $total gt 1000}{debug}{/if}
{/orders}

Expressions and labels

Any expression is evaluated; name=expression puts a label on its box.

Templateexamples/debug/3-labels.src
{debug $cart, vat=$total * 0.21, $typo}

See also

  • {dump} Stops the request and shows the debug dump of the engine's state at that point.
  • {trace} Switches the execution trace on for just the part of the page it wraps.
  • {jsonview} A JSON value or a PHP array as a tree that folds open and shut, coloured by type.