/var/www/vhosts/disorder.de/script/public_html/tpl/rightblock.tmpl Script.gr - PHP Scripts, HowTos and Tutorials
Requirements
Simple Template Parser is tested to work on
  • Webserver Apache 1.3.x or 2.x
  • PHP 4.0+
  • Linux, Windows, MacOSX and FreeBSD
Installation
  1. Unpack the archive
  2. Move the file parser.inc to any place that suits you.
  3. include parser.inc in your file
  4. Have fun!

Reference
For the impatient,you can move on to the Examples to get a quick start.
However, we recommend you learn at least the basic commands. It is really easy and it is always good to know what you are doing.

Calling STP

Include parser.inc in your file :
require_once("PATH_TO/parser.inc");
Then create a new instance of the parser object:
$STP = new parser2;

Public methods

getParams Returns all set parameters getParam($name) Returns the parameters $name setParam($name, $value) Sets one parameter with the name $name and the value $value setParams(&$params) sets several parameters at once
accepts an array or an object that supports the method getVar($name) clearParams($array = 'all') Deletes all parameters (no argument) or a list of parameters from an array (the parameters can be keys or values) clearParam($name) Deletes one parameter defined by its name $name assemble($frame, $frags) Assembles a template from a frame document and fragments setTemplate($tmpl) Load a monolithic (i.e. standalone) template setTemplateText($text) Sets the template content directly (not through a file) setTemplateText($text) Sets the template content directly (not through a file) parseAndReturn() Parse template and return the contents parseAndEcho() Parse template and ECHO the result to STDOUT parseAndEchoPHP() Parse template and ECHO the result to STDOUT; Evals One-line PHP code parseAndSave($file) Parse template and save the result to the file $file setIncludePath($path) Set include path (only 1 directory possible)
Call this before setTemplate!

Parser Tags

The following tags can be incorporated in your HTML templates: <#NAME#> This will be filled with the variable called $NAME set by the function setParam($NAME) or setParams(); <#FOR NAME#>...<#/FOR NAME#> Loops through the multi-dimensional array $NAME (see examples) <#IF NAME#>...<#/IF NAME#> Outputs the included HTML only if $NAME is set <#!IF NAME#>...<#/!IF NAME#> Outputs the included HTML only if $NAME is not set <#IF NAME (eq Condition)#>...<#/IF NAME#> Outputs the included HTML only if $NAME is equal to the string or number Condition <#IF NAME (ne Condition)#>...<#/IF NAME#> Outputs the included HTML only if $NAME is NOT equal to the string or number Condition <#IF NAME (gt Condition)#>...<#/IF NAME#> Outputs the included HTML only if $NAME is greater than the number Condition <#IF NAME (ge Condition)#>...<#/IF NAME#> Outputs the included HTML only if $NAME is greater than or equal to the number Condition <#IF NAME (lt Condition)#>...<#/IF NAME#> Outputs the included HTML only if $NAME is lower than the number Condition <#IF NAME (le Condition)#>...<#/IF NAME#> Outputs the included HTML only if $NAME is lower than or equal to the number Condition <#IF NAME (lk Condition)#>...<#/IF NAME#> Outputs the included HTML only if the string Condition $NAME is contained in Condition <#ATTR VALUE1, VALUE2...#> Must be in the head of the template; value1 and Value2 can be color values or CSS class/id names.
This tag is complemented by <#ATTR> Will be filled with the alternating values defined in <#ATTR....#> above <--INSERT_FRAGMENT--> Inserts the Fragment defined as "FRAGMENT" into the defined place in the master template

Constant handling

If you declare constants that start with "G_" they will be available in the parser templates automatically without passing them. Example: define("G_WEBROOT", "http://" . $_SERVER['HTTP_HOST']) will be available to the template as <#G_WEBROOT#> and output something like
http://www.mywebsite.com

Alternative parser

If you cannot use <# ... #> as tag delimiters or you don't want to: Call $STP = new AlternativeParser instead of parser2.
This will let you use [...] instead as tag delimiters, like
[IF SOMETHING]
This is [SOMETHING]
[/IF]
instead of
<#IF SOMETHING#>
This is <#SOMETHING#>
<#/IF#>

My Sites