Below I'll describe the options that you can use when configuring vlibTemplate to work to your needs.
All of the following options detailed below can be edited in your vlibIni.php file (called vlibIni.php-dist in the archive).
Each option can be set in the vlibIni.php file which will mean that this value is taken as a default for each template file you use, or they can be set in an array as the second parameter to vlibTemplate() the main class constructor.
-
TEMPLATE_DIR
- the default include path to you where you store your templates.
This option can make it easier for you to access your templates when scripting.
-
MAX_INCLUDES
- to avoid recursive includes using <tmpl_include>,
this options sets the include depth that vlibTemplate will drill down when including files. Defaults to 10.
-
GLOBAL_VARS
- When you use a <tmpl_var> tag inside a loop and the loop variable is null vlibTemplate will
check the global scope as well, if this option is set to 1.
-
GLOBAL_CONTEXT_VARS
- when set to 1, the following variables are made available in the global scope.
NB: more variables may be added in the future. All variable start and end with 2 underscores.
-
__SELF__ - this variable value is the value of $PHP_SELF.
-
__REQUEST_URI__ - same as __SELF__ but appends any GET method parameters.
-
__PARSE_TIME__ - time taken to parse template. Only used when TIME_PARSE option is set to 1.
-
LOOP_CONTEXT_VARS
- when set to 1, the following variables are made available within the scope of each <tmpl_loop>.
NB: more variables may be added in the future.
-
__FIRST__ - is true when you are currently on the first row of the loop.
-
__LAST__ - is true when you are on the last row of the loop.
-
__INNER__ - is true when you are on neither the first or last row of the loop.
-
__EVEN__ - is true when you are on an even row of the loop.
-
__ODD__ - is true when you are on an odd row of the loop.
-
__ROWNUM__ - an integer of the current row number starting at 1.
-
SET_LOOP_VAR
- because global variables and loop variables are handled seperately in vlibTemplate, to use a
<tmpl_if/unless/elseif> on a loop you must set this option to 1. This will in turn set a variable to
true in the global scope with the same name as the loop only if the loop is not empty.
-
DEFAULT_ESCAPE
- when using the template in an html-based application you should escape most of the string passed into
the template using htmlspecialchars(). This option will allow you to specify a default escape type for all
of your <tmpl_var>'s. To overwrite this option, you can either use a different setting when instantiating
vlibTemplate using the options array, or on per tag basis i.e. <tmpl_var name="varname" escape="url">.
The following values are all possible escape values.
NB: more escape attributes may be added in the future.
-
HTML - html escapes a string.
-
URL - url escapes a string.
-
RAWURL - rawurl escapes a string.
-
SQ - escapes single quotes in a string.
-
DQ - escapes double quotes in a string.
-
NONE - turns off escaping.
-
1 - alias for html escaping.
-
0 - alias for NONE. (1 and 0 are for compatibility with Perl's HTML::Template).
-
HEX - hex encodes a string.
-
HEXENTITY - encodes a string to hex entities.
-
STRICT
- when set to 1, vlibTemplate will die() upon finding an incorrect <tmpl>'esque tag. i.e.
<tmpl_vat name="varname">
-
CASELESS
- when set to 1, vlibTemplate will become case-INSENSITIVE. setVar('myvar1') will be called even using
<tmpl_var name="mYvAr1">.
NB: All <tmpl_*> tags are case INSENSITIVE, this option refers to the variable and loop names.
-
UNKNOWNS
- will define how variables like <tmpl_var name="myvar"> are handled if they have not been set using setVar().
-
IGNORE - (default) completely ignores the unfound variable.
-
REMOVE - removes the <tmpl_var> tag, but notes the tag for use with the unknown functions.
-
LEAVE - will leave the tag as it is, and note it.
-
PRINT - escapes the actual unknown tag using html encoding.
-
COMMENT - comments out the tag using html style comments, and note it.
-
TIME_PARSE
- when set to 1, vlibTemplate will time how long it takes to parse the template. see getParseTime().
If TIME_PARSE and GLOBAL_CONTEXT_VARS are both set to 1, then a Global var
called __PARSE_TIME__ is set with the time it took to parse the template.
-
ENABLE_PHPINCLUDE
- Will allow template to include a php file using <TMPL_PHPINCLUDE>
-
CACHE_LIFETIME
- lifetime of the cached file in seconds. Defaults to 604800 seconds (1 week).
-
CACHE_EXTENSION
- extension used when caching files.