{trace}

Switches the execution trace on for just the part of the page it wraps.

Debugging and errors Tag pairs

Syntax

{trace} ... {/trace}

Description

{trace} ... {/trace} records how the engine processes its content: every level that starts and ends, every occurrence of a loop, the tags met and the content each level produced, with line numbers. It is the trace that $padInfo = 'trace' writes for a whole request, narrowed to the part you are interested in - a slow loop, a condition that takes the wrong branch - so the trace stays readable.

The page itself is not changed: the content renders exactly as without the tag. The trace goes to files under DATA/trace/<page>/<request id>-<n>/ - root.txt with the outline, one line per event, and a local.txt per tag below it. On the way in the tag parks the request's own info settings and loads the default trace set (pad/config/info/trace.php: levels, occurrences, line numbers and results on; the noisier internals off); at {/trace} it closes the scope and puts back what was parked, so nothing outside the pair is traced.

A request cannot switch tracing on by itself - $padInfo is never filled from the query string. For a whole page use $padInfo = 'trace' in _config/config.php, or render it with php editors/render.php app page --trace. To look at a value rather than the execution, use {debug}.

Examples

Trace one loop

Only the loop inside the pair is traced; the output is the same as without the tag.

Templateexamples/trace/1-one-loop.src
<h2>Orders</h2>
{trace}
  {orders where='$total gt 100'}
    <p>{$number}: {$total}</p>
  {/orders}
{/trace}
<p>Not traced.</p>

What the trace writes

root.txt for a two-row loop: the level path, the event number, what it started from, the event and the result.

Templateexamples/trace/2-the-files.src
{trace}{sequence '1..2'}{$sequence}{/sequence}{/trace}

{# DATA/trace/<page>/<id>-0/root.txt - beside it trace/local.txt and trace/sequence/local.txt
1        1             trace     start
1/1      2             occur     start
2        3             level     start     {sequence '1..2'}
2/1      4             occur     start
2/1      5      4      occur     end       1
2/2      6             occur     start
2/2      7      6      occur     end       2
2        8      3      level     end       12
1/1      9      2      occur     end       12
1        10     1      trace     end       12
#}

See also

  • {debug} Shows values as a collapsible tree in the page, for a local request only, while rendering goes on.
  • {dump} Stops the request and shows the debug dump of the engine's state at that point.