{sandbox}
Runs its content as PAD source in an isolated pass that cannot see or leave behind anything of the page.
Syntax
{sandbox} ... {/sandbox}
{sandbox function='name'} ... {/sandbox}
{echo $snippet | sandbox}
Options
-
function - Runs the pass inside a PHP function of that name, with a variable scope of its own; being sandboxed, nothing is copied out.
Description
{sandbox}...{/sandbox} does what {code} does - renders its content as PAD source in a separate engine pass - with the pass sandboxed. It is {code sandbox} under a name of its own.
Sandboxed means: going in, the page's variables are hidden and the data, content, bool and sequence stores are emptied; coming out, everything is restored and what the pass set is gone. A field of the page is missing inside - write {echo $city ?? 'default'} when a snippet may run either way - and a {push} made inside fills the pass's own stacks, not the page's.
The pipe form, {echo $snippet | sandbox}, runs a value as a template in the same isolation. It is the safer choice for template text that comes from outside the code - an editor, a database - when that text should not read or change the page's state. It is not a security boundary for untrusted authors on its own: the template language can still call what $padPhpFunctions allows.
Examples
A sandboxed pass
The content renders in a pass of its own, like code.
<p>{sandbox}Three squared is {echo 3 * 3}.{/sandbox}</p>
Three squared is 9.
Nothing in, nothing out
Inside, the variables of the page are missing; what the pass sets is gone afterwards.
{set $city = 'Utrecht'}
<p>outside: {$city}</p>
<p>inside: [{sandbox}{echo $city ?? 'not visible'}{set $inner = 'x'/}{/sandbox}]</p>
<p>after: [{$inner | optional}]</p>
outside: Utrecht
inside: [not visible]
after: []
The sandbox pipe
A value run as PAD, isolated - a snippet kept elsewhere cannot touch the page.
{set $price = 10}
<p>code: {echo $snippet | code}</p>
<p>sandbox: {echo $snippet | sandbox}</p>
<?php
$snippet = 'price is {echo $price ?? \'unknown\'}';
?>
code: price is 10
sandbox: price is unknown
See also
- {code} Runs its content as PAD source in a separate engine pass and outputs what that pass produced.
- {page} Renders another page of the application - its PHP and its template - in place of the tag.
- {ignore} Keeps PAD from reading the braces in its content as tags - for inline JavaScript, CSS, JSON and code samples.