-
Notifications
You must be signed in to change notification settings - Fork 5
CMS template syntax
CMS templates define the output of a service according to the parameters provided at the service call, and the result of the service itself.
CMS templates are edited in the CMS module.
The general CMS template syntax is :
- the text is streamed as is
- commands are delimited by
<x ... x>
sequence, with x corresponding to one of the available CMS template operators, and … corresponding to the parameters of the CMS template operator.
Example :
Raw text
Other line
<@line@>
An other line with <@command@> inside
will output, with variables line=1 and command=2 :
Raw text other line 1 An other line with 2 inside
Operator | Description | Remark |
---|---|---|
<?…?> |
CMS template syntax#Service-call | See API_requests for services list |
< |
CMS template syntax#Variable-setting | |
< |
CMS template syntax#Map-variable-setting | |
< |
CMS template syntax#Expression-output | Mainly used to access text variables |
<@@> |
Display of each available variable | For debugging purpose |
<#…#> |
Template inclusion | |
<%…%> |
Goto instruction | |
<<…>> |
Line label | |
<{…}> |
Foreach instruction | Used to access array variables |
<?service_name¶m1=value¶m2=value?>
is equivalent to a HTTP call like this :
http://server_name/synthese?SERVICE=service_name¶m1=value¶m2=value
The parameter are separated by &. Each parameter is defined by the name=value syntax.
The value is evaluated. For example, name=<@var@> will set to the parameter called name the value of the variable var.
So, it is possible to encapsulate service calls :
<?service_name¶m1=value¶m2=<?service2¶m=value?>?>
Sometimes, services use templates to display the output. In this case, the template can access to each parameter set on the URL. Parameters set at the service call are not visible by the used template(s).
To send a parameter to the template at the service call, define a parameter with VAR prefix before its name :
<?service¶m1=value&VARparam2=value?>
In this example, the service will read only param1, and the template will access only to param2.
A service result is returned as a tree structure, which can be read by a template defined in the service call.
The template must be specified as the template
parameter of the call.
Example :
<form> <?service¶m1=value&template= <input name="name" value="<@name@>" /> <input name="surname" value="<@surname@>" /> ?> <input type="submit" value="OK" /> </form>
will output a form with the name and surname fields filled by the called service.
Notes :
- variables available on the page which has called the template are visible in the inline template : no need to use the VARxx parameters in this mode
- an inline template can recursively call services or other CMS syntax items like loops on array variables
The service can only access to the parameters defined in the call.
Set the repeat_parameters
to 1 if the service should access to all parameters defined in the URL too.
An action cannot be properly run in a CMS page.
A Old actions run allows to run an action using the
<?…?>operator.
<@expression@>
The operator outputs the result of the expression
An expression is composed by operands and operators.
Warning : do not put spaces in expressions : they would be considered as content.
Operands can be :
variables | identified by their name |
numbers | type them directly |
text | type them in quotes (escape internal quotes if necessary) |
expression | type them in parenthesis |
Operators can be :
…?…:… |
Ternary test operator (if … then … else …) | ||
…+… |
Addition | ||
…-… |
Subtraction | ||
…*… |
Multiplication | ||
…/… |
Division | ||
…%… |
Modulo | ||
…^ … |
Power | ||
… |
.. | Or | |
…&&… |
And | ||
… |
.. | Bitwise or comparison | |
…&… |
Bitwise and comparison | ||
…==… |
Identity check | ||
…!=… |
Difference check | ||
…>=… |
Superior check | ||
…>… |
Strictly superior check | ||
…<=… |
Inferior check | ||
…<… |
Strictly inferior check | ||
!… |
Not | ||
-… |
Negative | ||
~sqrt… |
Square root |
The variables are defined in several ways :
- default variables
- variables defined by the URL
- variables defined in CMS templates
- variables defined by the services
The following variables are defined by the system and are always available :
Variable | Content |
---|---|
host_name |
Host part of the URL (eg http://server/dir?param=2 returns server ) |
client_url |
Directory part of the URL (eg http://server/dir?param=2 returns /dir ) |
site |
ID of the site which the current template belongs to |
Each URL parameter is stored as a variable even if it is used by the used service.
Example : param1=23
stores the value 23
in the variable param1
.
A variable cannot be directly defined in the template code right now.
But when operators are used, and when other templates are called by the command, it is possible to define variables in a similar manner as URL variables :
-
at service call : variables prefixed with VAR keyword will be available in all CMS templates used by the service (example : if a service is called by
service¶m=1&VARvar=2&p=template
, the template called by the p parameter will see thevar
variable.) - at template inclusion : all parameters defined at the inclusion will be available in the called template
- at foreach instruction call : all parameters defined at the foreach instruction call will be available in the called template
Tip : for practical reasons, it can be useful to use variables to store recurrent values. To do this, it is possible to use two levels of template : the first template calls the second, defining all variables in the inclusion call.
Example :
First template :
<#second_template?var1=1&var2=2&var3=3#>
Second template :
Text
<@var1@> <@var2@> <var3
Other text
<@var1@> <@var2@> <var3
When a service calls a CMS template to do its output, variables are defined by the service to provide the result of the service to the template.
Each service provides different variables : see the API documentation for the detail of available variables depending on the context.
Sidebar
SYNTHESE Documentation
Specifications
Developer documentation
Database
API
CMS template syntax
Interoperability
Administrator manual