Reference - Parms functions - optional


App: manual - Page: fragments/page_2
PHP
HTML
fragments/page_2.pad
Result
<p>plain: [{code}{set $f1 = 'x'/}{/code}{$f1 | optional}]</p>
<p>reset: [{code reset}{set $f2 = 'x'/}{/code}{$f2 | optional}]</p>
<p>clean: [{code clean}{set $f3 = 'x'/}{/code}{$f3 | optional}]</p>
<p>sandbox: [{code sandbox}{set $f4 = 'x'/}{/code}{$f4 | optional}]</p>


App: manual - Page: fragments/requests_1
PHP
HTML
fragments/requests_1.pad
Result
<p>Hello {$who | optional}!</p>
<p><a href="?pages/requests_and_urls&who=world">say who you are</a></p>


App: manual - Page: fragments/requests_3
PHP
HTML
fragments/requests_3.pad
Result
<form method="post">
<input type="text" name="note" value="">
<input type="submit" value="send">
</form>
<p>The note said: {$note | optional}</p>


App: regression/framework - Page: build/a_meta_or_extends_inside_a_comment_is_left_alone
PHP
HTML
build/a_meta_or_extends_inside_a_comment_is_left_alone.pad
Result
{# {meta title='commented'} #}{-- {extends '_layouts/base'} --}[{$title | optional}]


App: regression/framework - Page: data/a_collection_reads_markdown_files_with_front_matter_as_rows
PHP
HTML
data/a_collection_reads_markdown_files_with_front_matter_as_rows.pad
Result
{collection 'posts', sort='date DESC'}
[{$slug}|{$title | optional}|{$date | optional}|{!body}]
{/collection}


App: regression/framework - Page: expressions/a_fallback_hands_a_date_object_on_as_the_moment_it_holds
PHP
expressions/a_fallback_hands_a_date_object_on_as_the_moment_it_holds.php
HTML
expressions/a_fallback_hands_a_date_object_on_as_the_moment_it_holds.pad
Result
<?php

$moment
= new DateTimeImmutable ( '2020-01-01T03:00:00+03:00' );

?>
[{echo $moment | date('U')}][{echo ($moment ?? 'none') | date('U')}][{echo ($nothing ?? $moment) | date('U')}][{echo $moment | default('x') | date('U')}][{$moment | optional | date('U')}][{echo [$moment ?? 'none'] | php:count}]


App: regression/framework - Page: expressions/a_field_a_fallback_takes_may_be_missing_in_brackets_and_by_any_prefix
PHP
HTML
expressions/a_field_a_fallback_takes_may_be_missing_in_brackets_and_by_any_prefix.pad
Result
[{echo ($missing) ?? 'none'}][{echo ((field:missing)) ?? 'none'}][{echo $missing | pad:default('x')}][{$missing | pad:default('y')}][{echo $missing | function:default('z')}][{echo ($missing | optional) . '!'}]


App: regression/framework - Page: expressions/a_field_piped_into_a_fallback_may_be_missing_in_echo_too
PHP
expressions/a_field_piped_into_a_fallback_may_be_missing_in_echo_too.php
HTML
expressions/a_field_piped_into_a_fallback_may_be_missing_in_echo_too.pad
Result
<?php

// A field piped into a fallback - default(), ??, optional - may be missing under the strict
// check in {echo} and inside an expression too, not only in {$x | ...}: they named it missing.

$user = [ 'name' => 'Ann' ];
$xs = [ [ 'n' => 1 ], [ 'n' => 2, 'm' => 5 ] ];

?>
[{echo $user.middle | default("-")}][{echo $user.middle | ?? "-"}][{echo $user.middle | optional}][{echo $user.name | default("-")}] {xs where='$m | ?? 0 | @ gt 1'}{$n}{/xs}


App: regression/framework - Page: expressions/a_missing_field_piped_into_a_prefixed_default_is_no_error
PHP
HTML
expressions/a_missing_field_piped_into_a_prefixed_default_is_no_error.pad
Result
{echo ($nope | pad:default('x'))} {echo upper($nope | function:default('y'))} {if ($nope | pad:optional) eq ''}empty{/if}


App: regression/framework - Page: passes/a_function_pass_copies_what_it_created_out
PHP
HTML
passes/a_function_pass_copies_what_it_created_out.pad
Result
{code function='psFn1'}{set $psV1 = 'q'/}F{/code}
[{$psV1 | optional}]


App: regression/framework - Page: passes/a_plain_pass_leaks_what_it_created
PHP
HTML
passes/a_plain_pass_leaks_what_it_created.pad
Result
{code}{set $nzN = 'q'/}{/code}[{$nzN | optional}]


App: regression/framework - Page: passes/a_sandboxed_function_pass_does_not
PHP
HTML
passes/a_sandboxed_function_pass_does_not.pad
Result
{code function='psFn2', sandbox}{set $psV2 = 'q'/}F{/code}
[{$psV2 | optional}]


App: regression/framework - Page: passes/clean_unsets_what_the_pass_created
PHP
HTML
passes/clean_unsets_what_the_pass_created.pad
Result
{code clean}{set $nzC = 'q'/}{/code}[{$nzC | optional}]


App: regression/framework - Page: passes/reset_leaks_it_too_reset_restores_it_does_not_unset
PHP
HTML
passes/reset_leaks_it_too_reset_restores_it_does_not_unset.pad
Result
{code reset}{set $nzR = 'q'/}{/code}[{$nzR | optional}]


App: regression/framework - Page: passes/sandbox_unsets_it_as_well
PHP
HTML
passes/sandbox_unsets_it_as_well.pad
Result
{code sandbox}{set $nzS = 'q'/}{/code}[{$nzS | optional}]