Options of your own
A file in the application's _options/ directory makes its name an option of every tag - written bare, {staff words}, or with a value, {staff wrap='em'}. Where the file stands decides when it runs:
| file | runs |
$padContent is
|
|---|---|---|
_options/name.php
|
before the tag renders | the template between the tags |
_options/end/name.php
|
after the tag rendered | the result - every occurrence, joined |
The handler changes $padContent, and the option's value is in $padGetName - TRUE when the option is written bare. An end option sees the fields filled in, so it can count, mark or tidy what the tag produced. Here fragments/options/_options/end/words.php appends a word count:
<?php // _options/end/words.php
$padContent .= '(' . str_word_count ( strip_tags ( $padContent ) ) . ' words)';
?>
|
PHP |
HTML fragments/options/options_1.pad |
Result |
|---|---|---|
|
joe jim john jack jerry (5 words) |
With a value - _options/end/wrap.php puts the result in the element it is given:
<?php // _options/end/wrap.php
$padContent = "<$padGetName>" . trim ( $padContent ) . "</$padGetName>";
?>
|
PHP |
HTML fragments/options/options_2.pad |
Result |
|---|---|---|
|
joe jim john jack jerry |
An option may have both files: the first works on the template, the second on what it became. The end options run before the built-in toContent, toData and tidy - those store or tidy what the end option made - and before the closing tag's pipe. Like tags and callbacks they are looked up from the page's directory up to the application root.