Nested Passes - {code} and {page}
A nested pass is the engine run inside itself: the content of a {code} pair, or the page a {page} tag names, is rendered as a complete PAD run of its own, and what it produced lands in the surrounding page. The pass sees the request it runs in - its variables, its stores - unless it asks for isolation.
A pass and what it leaves behind
A plain {code} shares everything. What the pass creates is still there when it returns:
|
PHP |
HTML fragments/page_1.pad |
Result |
|---|---|---|
|
The pass ran
After it: and left this behind |
The four isolation forms
Three options decide how much of the request a pass sees, and how much of the pass the request keeps. They differ on both sides of the boundary:
| form | sees the outer state | what it created afterwards |
|---|---|---|
{code}
|
yes | still there |
{code reset}
|
no - a blank slate going in | still there |
{code clean}
|
yes | taken back out |
{code sandbox}
|
no | taken back out |
|
PHP |
HTML fragments/page_2.pad |
Result |
|---|---|---|
|
plain: [x] reset: [x] clean: [] sandbox: [] |
Another page as a pass
{page 'name'} runs that page - its .php and its .pad - as a pass, with the same isolation options. A function option runs the pass inside a PHP function body, but it still starts from the caller's variables and what it sets comes back out - a page whose .php half must not touch the caller's variables wants clean or sandbox:
|
PHP |
HTML fragments/page_3.pad |
Result |
|---|---|---|
|
Hello World ! |
Stores cross the boundary by the same rules
The data, content, bool and sequence stores follow the isolation form. A clean pass reads the request's stores; a sandbox or reset pass starts without them. On the way out, only a plain pass's pushes stay: each of the three isolated forms puts the request's stores back exactly as they were, its own pushes included:
|
PHP |
HTML fragments/page_4.pad |
Result |
|---|---|---|
|
A clean pass sees the store: apple pear A plain pass pushed nums, and it survived: 7 8 9 |
Engine state is always put back
Whatever the isolation form, the engine itself returns to where it was: a loop the pass ran inside continues from the same row, and a request-lived counter such as {switch}'s rotation is rolled back with the rest - a pass takes its counting with it:
|
PHP |
HTML fragments/page_5.pad |
Result |
|---|---|---|
|
Inside a pass: first After it: first |
Both calls answer the first value: the rotation the pass advanced was restored when the pass returned.