![]() |
Flat-Frog - the faster compiling PHP template engine |
PHP ============================= $tpl->assign("foo","bar"); TEMPLATE ============================= <% $foo %> OUTPUT ============================= bar
PHP ============================= $foo = array("apples", "oranges", "bananas"); $tpl->assign("foo", $foo); TEMPLATE ============================= <% $foo %> <% $foo[0] %> OUTPUT ============================= Array apples
PHP ============================= $foo = array("fruit" => "apples", "vegetable" => "carrot", "dairy" => "milk"); $tpl->assign("foo", $foo); TEMPLATE ============================= <% $foo[fruit] %> <% $foo[dairy] %> OUTPUT ============================= apples milk
After you have loaded a config file, you might want to reference the variables you have loaded from your template. Config variables are more like static constants in that they cannot be changed from the template and are thus referred to differently than normal variables. They are offset by hash or pound marks (#) on either side of the variable.
CONFIG FILE (config.ini) ============================= foo = "bar" test = "this is a string" TEMPLATE ============================= <% config_load file="config.ini" %> <% #foo# %> OUTPUT ============================= bar
Variables in quotes are handled exactly the same in Flat-Frog as they are in PHP. Here are some examples:
<% "test $foo test" %> <- sees $foo <% "test $foo_bar test" %> <- sees $foo_bar <% "test $foo[0] test" %> <- sees $foo[0] <% "test $foo[bar] test" %> <- sees $foo[bar] <% "test $foo.bar test" %> <- sees $foo (not $foo.bar) <% "test `$foo.bar` test" %> <- sees $foo <% 'test $foo test' %> <- will interpret literally <% "test \$foo test" %> <- will escape the variable and return $foo literally
The are two ways to concatenate variables using Flat-Frog. The first is using the standard PHP-compliant 'dot' syntax. The other is to use a comma syntax. Here are some examples of each way.
PHP ============================= $tpl->assign("foo","bar"); $tpl->assign("name","Paul"); TEMPLATE ============================= <% $foo.$name %> <% $foo." ".$name %> <% $foo, $name %> <% $foo, " ", $name %> OUTPUT ============================= barPaul bar Paul barPaul bar PaulThe comma concatenation technique works only as a standalone tag, i.e.
<% $foo, $bar %>
but not <% func arg=$foo, $bar %>
, whereas the 'dot' syntax works in all cases where a variable is accepted.
Using the $_TPL variable, you can refer to special environment variables from inside the template.
<%* display value of page from URL (GET) http://www.domain.com/index.php?page=foo *%> <% $_TPL[GET][PAGE] %> <%* display the variable "page" from a form (POST) *%> <% $_TPL[POST][PAGE] %> <%* display the value of the cookie "username" *%> <% $_TPL[COOKIE][username] %> <%* display the server variable "SERVER_NAME" *%> <% $_TPL[SERVER][SERVER_NAME] %> <%* display the system environment variable "PATH" *%> <% $_TPL[ENV][PATH] %> <%* display the php session variable "id" *%> <% $_TPL[SESSION][id] %> <%* display the current time in unix epoch form *%> <% $_TPL[NOW] %>