Please enable JavaScript to view this site.

Navigation: Advanced topics > Programming topics

Template language

Scroll Prev Next More

 

Template language is the framework that powers visual and code templates in PHPRunner. Most template language expressions are references to the project files. 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 the @ character.

 

Examples:

 

@BUILDER - the root element of the project file.

@TABLE - a pseudo-variable that points to the currently selected table.

@a, @field - regular variables.

@TABLE.arrFieldObj - an array of fields that belong to the current table.

@field.EditFormatObj.m_strDefaultValue - the 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. The comparison result can be either 0 or 1.

2. Boolean

or or ||

and or &&

not or !

 

The result can be 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 dot . operator is used.

 

Example:

 

@field.m_ListFormatObj.m_nColWidth

5. The Array length property is '.len'

Example:

 

@TABLE.m_arrFieldObj.len

6. Priority order

There is an established order with the priority of each operator. From greatest to lowest, the priority order is as follows:

 

1. .

2. .len

3.parenthesis

4.comparison operators

5. not

6. and

7. 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 the field label, for example, '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

1)

 

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##

 

2)

 

Repeat <number> [variable], endrepeat

 

Repeat the loop body N times. Variable, if specified, ranges from 1 to <number>.

 

3)

 

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##
 ##if @first##
   include("include/validate.phpaspcs");
 ##endif##
##endfor##

 

4) Nested loops.

 

Repeat and Foreach loops can be nested.

 

Example:

 

##foreach @BUILDER.Tables as @t##
 ##foreach @t.arrMasterTables[strMasterTable==@TABLE.strDataSourceTable].arrMasterKeys as @dk##
 $masterquery.="&masterkey##@index##=".rawurlencode($data["##@dk s##"]);
 ##endfor##
 $showDetailKeys["##@t.strShortTableName##"]=$masterquery;
##endfor##

 

5) Loop variable @index

 

The loop variable @index takes on the values 1, 2, ..., N through each of the N iterations of the loop body.

 

6) Pseudo-variables @first and @last

 

The @first variable takes the value of:

 

1 - during the first loop pass;

0 - otherwise.

 

It is 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##

 

In loops, @first terminates the execution of the nearest enclosing foreach or repeat statement. Control then passes to the statement that follows the terminated statement, if any:

 

##foreach @TABLE.m_arrFieldObj as @field##
##if @field.m_EditFormatObj. m_strValidateAs && @first##
 include("include/validate.phpaspcs");
##endif##
##endfor##

 

7) Order - a sort order other than default.

 

Example. Get a list of fields ordered by nEditPageOrder (the field order on the edit page):

 

##foreach @TABLE.m_arrFieldObj as @field order @field. nEditPageOrder##
##if @field.m_EditFormatObj. m_strValidateAs && @first ##
 include("include/validate.phpaspcs");
##endif##
##endfor##

Output modifiers

Modifiers are required to encode quotes, slashes and other characters that can break template language elements. You can combine several modifiers. Modifier order is important.

 

Example:

 

##@field.m_strLabel hs##

List of modifiers abbreviations:

hs - shapehtml is applied first, shapescript is applied after that.

s - replaces " with \" for PHP.

q - strings wrapped by single quotes.

h - HTML-encodes the string.

j - replaces ' with \'.

n - replaces spaces with &nbsp.

u - URL-encodes the string.

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`).

g - replaces all non alphanumeric characters with underscores.

p - builds the parameter name for UPDATE, INSERT, DELETE (.NET specific).

c - removes spaces.

8 - converts a UTF8 string to a national language charset.

o - removes the owner/schema from table name.

d - converts the name to CamelCase. Example: "Order details" becomes OrderDetails.

l - replaces line feeds and carriage returns with spaces.

a - builds a valid variable name from the table name. Used in Data Access Layer.

f - builds a valid variable name from the field name. Used in Data Access Layer.

x - builds a valid property name (.NET Data Access Layer specific).

y - builds a valid class name (.NET Data Access Layer specific).

Macros and constants

Macros and constants are processed and replaced with the actual code. Macros and constants are defined in the 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 in the same way. Therefore, we suggest to follow this naming convention: constant names are written in upper case (e.g., FORMAT_DATABASE_IMAGE), macro names use CamelCase convention (e.g. UseCalendar). Spaces are not allowed in macro or constant names.

 

Example:

 

##if @field.strViewFormat==FORMAT_DATABASE_IMAGE##
##if UseRTE(@field)##
##foreach Fields as @f##
##Master.strCaption##

Additional language elements

Specific array element

 

To access a specific array element, use <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.

See also:

PHPRunner templates

Template files processing rules (Files.txt)

 

Created with Help+Manual 7 and styled with Premium Pack Version 3 © by EC Software