-
Notifications
You must be signed in to change notification settings - Fork 57
Documentation for web designers
RainTPL is an easy PHP template engine, it loads simple HTML templates with tags. A template can looks as the following index.html file:
<!DOCTYPE html>
<html>
<head>
<title>{$title}</title>
</head>
<body>
{$content}
</body>
</html>
By default the template are saved into the themes folder, which can be changed in the configuration.
- {$variable}
- {#constant#}
- {include="template"}
- {if="espression"}
- {loop="$array"}
- {function="function name"}
- {/* comment */}
- {noparse}
Variables are the dynamic contents of the template, valorized in the execution of the script with RainTPL assign() method. Variable names are case sensitive.
example
{$name}, I am your father!
output
Luke, I am your father!
You can execute mathematical operations with variables, assignment and even add modifiers. Modifiers are function executed on the variables
example
{$a=1}
{$b=2}
{$sum=$a+$b}
example
{$title|cut:10} // Hello Wor...
{$title|touppercase|cut:7} // HELLO W...
You can access the constants defined in the PHP code using the tag {#constant#}
** example
{#URL#}
http://raintpl.com
With this tag you can include external template as blocks, for example you can include the header and the footer:
example
<html>
<body>
{include="header"}
here goes the content of the website
{include="footer"}
</body>
note: you can use a variable to dynamically load a template, for example {include="$page"}
##{if="expression"} Checks an expression and print the code between {if}{else} if the condition is true or {else}{/if} if the condition is false:
example
{if="$age<18"}
minor
{else}
adult
{/if}
##{loop="$var"} This tag allow to loop thru the value of arrays or objects.
example
<ul>
{loop="$weekday"}
<li>{$key}, {$value}</li>
{/loop}
</ul>
**output
<ul>
<li>0, Sunday</li>
<li>1, Monday</li>
...
<li>6, Saturday</li>
</ul>
Between {loop} and {/loop} few variables take special values such as:
- {$key}, the key of the current element of the array
- {$value}, the value of the current element of the array
- {$counter}, count the loops starting from 0 increasing each time by 1
Use this tag to execute a PHP function and print the result. You can pass strings, numbers and variables as parameters.
example
{function="date('%Y')"}
output
2013
Everything between {/* and */} is commented out:
example
Hey {/\* {$name} what's up \*/} dude?
output
Hey dude?
Everything between {noparse} and {/noparse} won't be compiled:
example
{noparse}this is the {$title}{/noparse}
output
this is the {$title}