Extending PAD
An application teaches PAD new words by putting files in the right directory - no registration, no configuration. The file's name is the name in the template.
A tag of your own: _tags/
A file _tags/badge.php makes {badge} a tag. The file reads its parameters with padTagParm ( name, default ) and returns what it renders - a value, whose braces stay text; $padContent is template source, so nothing built from a parameter goes there. The app: prefix names it explicitly when another meaning of the name is in the way:
|
PHP |
HTML fragments/extending_1.pad |
Result |
|---|---|---|
|
«new» «plain» «explicit» |
<?php // _tags/badge.php
$label = padTagParm ( 'label', 'plain' );
return '«' . htmlspecialchars ( $label ) . '»';
?>
A pipe function: _functions/
A file _functions/stars.php makes | stars a pipe. The file gets the piped text as $value, its parameters as $parm, and returns the answer - and it chains with everything else:
|
PHP |
HTML fragments/extending_2.pad |
Result |
|---|---|---|
|
*** well done *** *** WELL DONE *** |
A snippet: _include/
A file _include/tip.pad is template, dropped in wherever its name is written - bare, or with the include: prefix:
|
PHP |
HTML fragments/extending_3.pad |
Result |
|---|---|---|
|
Tip: the parser likes a single tag closed with a trailing slash. Tip: the parser likes a single tag closed with a trailing slash. |
Functions for every page: _lib/
Every .php file in _lib/ is included on every request, so a page's PHP half calls what they define without an include of its own:
|
PHP fragments/extending_4.php |
HTML fragments/extending_4.pad |
Result |
|---|---|---|
|
|
hear me hear me |
The whole family
| directory | a file there is |
|---|---|
_tags/
|
a tag |
_functions/
|
a pipe function |
_include/
|
a template snippet |
_lib/
|
PHP functions, included every request |
_callbacks/
|
a data iteration hook - see callback |
_options/
|
a tag option of your own - see options of your own |
_events/
|
a hook for an error, a query, a fetch or the finished page - see event hooks |
_data/
|
a data file, usable as a tag - see the data tag |
_scripts/
|
a shell script, run by the script: prefix
|
A subdirectory may carry any of these of its own: its pages see both, and its version of a name wins - the story of the application structure page.