{true}

The constant TRUE: its content renders once, as a level of its own.

Conditions Either form

Syntax

{true}
{true} ... {/true}

Description

{true} answers TRUE - the plain hit of a level. Written as a pair, its content renders exactly once and there is no data to iterate; written alone it prints nothing. It is the fixed "yes" of the three constant tags, beside {false} and {null}.

Its use is as a neutral level to hang options on. Every tag takes the generic options, so {true tidy}...{/true} tidies a stretch of HTML, {true toContent='box'} keeps its rendered content in a store, and {true $total = 0}...{/true} gives a block a variable of its own that is unwound when the block closes. In tests it switches a branch on without changing anything else.

Because it is a hit, an @else@ part of a {true} never renders.

Examples

A block that always renders

The content of {true} renders once; flip it to {false} to switch the block off.

Templateexamples/true/1-block.pad
<p>Before.</p>
{true}
  <p>This part is switched on.</p>
@else@
  <p>Never shown.</p>
{/true}
<p>After.</p>
Resultopen alone

Before.

This part is switched on.

After.

A level for options

{true} as a neutral level: a variable of its own that is gone after the block.

Templateexamples/true/2-level.pad
{set $label = 'outside'}
{true $label = 'inside'}
  <p>In the block: {$label}</p>
{/true}
<p>After the block: {$label}</p>
Resultopen alone

In the block: inside

After the block: outside

See also

  • {false} The constant FALSE: its content is skipped and its @else@ part renders instead.
  • {null} The constant NULL: its content is dropped, the @else@ part too, and a null= option fires.
  • {if} Renders its content only when a condition holds, with elseif and else branches.