|
Template language is the framework that powers visual and code
templates in PHPRunner. Most template language expressions are
references to the project file. Template language elements are
wrapped by ## characters:
##if @field.m_bAddPage##
Expressions
1. Strings
Example:
"string1" - string1 "this is a \"string\"" - this is a "string"
"\"\\\" is a backslash" - "\" is a backslash
2. Numbers
Examples:
2
3.3
-2
3. Variables
Variables start with @ character
Examples:
@BUILDER - root element of project file, @BUILDER.
@TABLE - pseudo-variable that points to the current selected table
@a, @field - regular variables
@TABLE.arrFieldObj - array of fields that belong to the current table
@field.EditFormatObj.m_strDefaultValue - default field value
Variables belong to one of the following data types: strings,
numbers, objects and arrays.
4. Boolean expressions
0,"" - false, anything else - true
Operators
1. Comparison operators
== - equals
= or <> - does not equal
< - less than
<= - less than or equal to
> - greater than
>= - greater than or equal to
You can only compare numbers and strings. Comparison result is either
0 or 1.
2. Boolean
or or ||, and or && , not or !
Result is either 0 or 1
3. Parenthesis
Example:
(@field.m_bAddPage or @field.m_strLabel=="ID") and not @Table.m_strCaption==""
4. Dot operator
To access structure members, the operator used is the dot operator
denoted by (.).
Example:
@field.m_ListFormatObj.m_nColWidth
5. The Array length property is 'len'
Example:
@TABLE.m_arrFieldObj.len
6. There is an established order with the priority of each operator.
From greatest to lowest priority, the priority order is as follows:
.
.len
parenthesis
comparison operators
not
and
or
Statements
1. Display a value of a variable or an expression
Examples:
##3## - displays 3
##@field.m_bAddPage## - displays 0 or 1
##@field.m_strLabel## - displays 'Year of Make'
2. Conditional statement
if <Boolean expression>, elseif <Boolean expression>,
else, endif
Examples:
##if @field.m_bAddPage##
...
##elseif @field.m_strLabel=="ID"##
...
##else##
...
##endif##
3. Loop statements
Foreach <array> as <variable> , endfor
The Variable is created when loop starts and destroyed with the 'endfor'
Example:
##foreach @TABLE.m_arrFieldObj as @field##
if strField="##@field.m_strName##" then
Label = "##@field.m_strLabel##"
##endfor##
Repeat <number> [variable], endrepeat
Repeat loop body N times. Variable, if specified, ranges from 1 to <number>
Break
Quits the loop. In loops, break
terminates execution of the nearest enclosing foreach or repeat
statement. Control then passes to the statement that follows the
terminated statement, if any.
Example:
##foreach @TABLE.m_arrFieldObj as @field##
##if @field.m_EditFormatObj. m_strValidateAs##
include("include/validate.php");
##break##
##endif##
##endfor##
order - sort order other than default.
Example:
Get a list of fields ordered by nEditPageOrder (field order on the
edit page)
##foreach @TABLE.m_arrFieldObj as @field order @field. nEditPageOrder##
##if @field.m_EditFormatObj. m_strValidateAs##
include("include/validate.php");
##break##
##endif##
##endfor##
Filter
Allows nodes filtering.
Example:
Get a list of fields that require validation:
##foreach @TABLE.m_arrFieldObj as @field filter
@field.m_strValidateAs order @field. m_nEditPageOrder##
include("include/validate.php");
##break##
##endfor##
Pseudo-variables @first and @last
@first
1 - during the first loop pass
0 - otherwise
Useful when you need to perform some action only once i.e. skip a
comma in front of table name:
$tables = Array("Table1","Table2","Table3");
##if !@first## , ##endif##
Output modifiers
Modifiers are required to encode quotes, slashes and other
"bad" characters that can break template language elements:
1. shapescript - replace " with "" for ASP and "
with \" for PHP
2. shapesinglequote - PHP strings wrapped by single quotes
2. shapehtml - similar to HTMLEncode
3. shapejavascript - replace ' with \'
You can combine several modifiers. Modifiers order is important.
Example:
##@field.m_strLabel hs##
hs - shapehtml will be applied first, shapescript will be applied
after that.
List of modifier abbreviations:
s - shapescript
q - shapesinglequote
h - shapehtml
j - shapejavascript
n - replace spaces with
u - Urlencode
w - adds wrappers around the field name ([field name] or `field name`)
t - adds wrappers around the table name ([dbo].[table name] or `table name`)
Macros and constants
Macros and constants processed and replaced by the actual code.
Macros and constants are defined in macros.txt file.
Constant definition example:
##define <name> <value>##
##define FORMAT_DATABASE_IMAGE "Database image"##
##define EDIT_DATE_SIMPLE 0##
Macro definition example:
##define UseRTE(@field)
(@field.strEditFormat==EDIT_FORMAT_TEXT_AREA && @field.m_EditFormatObj.m_bUseRTE)
##
Macros and constants are processed the same way. We suggest to follow
this naming convention: constant names all upper case
(FORMAT_DATABASE_IMAGE), macro names use CamelCase convention
(UseCalendar). Spaces are not allowed in macro or constant names.
Usage examples:
##if @field.strViewFormat==FORMAT_DATABASE_IMAGE##
##if UseRTE(@field)##
##foreach Fields as @f##
##Master.strCaption##
Additional language elements
1. Access specific array element
<array>[<condition>]
Example:
##@TABLE.arrFieldObj[strName==@TABLE.strKeyField].strLabel##
This example shows how to access the Label property of a key column
field (or any other field).
|