Kauri Documentation
 PreviousHomeNext 
8.4 Syntax referenceBook Index8.4.3 Template inheritance

8.4.2 Expression language

Expressions can be used to insert dynamic content into the generated output or to provide arguments to template instructions (e.g. the "test" attribute of an <if> instruction).

Kauri template supports two expression languages:

Normally, you should have enough with EL and never touch Groovy.

Groovy offers a powerful escape for those who know what they're doing.

8.4.2.1 EL

The default expression language is the Unified Expression Language (EL), which is the same as used by JSP.

You can type your EL expressions using the ${...} or #{...} delimiter.

Note: when just using the expression language (thus no template directives), there is no need to declare the template namespace. The ${} and #{} delimiters will be picked up automatically when passed to the template engine. If you want to use the $ or # character as regular text, you have to escape it with  a backslash: \$ and \# .

8.4.2.1.1 Expressions

Some of the supported expressions are:

You can access objects that are supplied to the context of the tempate engine by referencing their keys. With the dot-operator, you can access the properties of those objects, e.g.: you can use the expression ${request.clientInfo.acceptedMediaTypes} when there is a request object supplied to the execution context.

8.4.2.1.2 Functions

There are also some convenience functions available. These are called using prefix:name(), for example txt:concat('foo', 'bar').

8.4.2.1.2.1 Text functions
8.4.2.1.2.2 Math functions

Actually all the functions of java.lang.Math are available as EL functions with prefix math. While this is very handy and powerful, you have to keep in mind that this also means that newly added math functions will be only available depending on the JRE used to run your application.

8.4.2.1.2.3 Date/time functions
8.4.2.1.2.4 JSON functions

Remember to escape '<', '>' and '&' characters when using EL expressions in XML files.

8.4.2.1.3 Kauri-specific functions

These are functions only available when using the template engine within Kauri (using the kauri-template-service module).

8.4.2.1.3.1 publicUri(uri)

If the argument is a URI that uses the service protocol, then the URI will be translated to a public URI, this is a URI that can be used to call the service from outside Kauri. This will only work if the REST-service addressed by the URI is mounted on a path (in the wiring.xml). If the REST-service would be mounted on a virtual host which differs from the host of the current (non-internal) request, then the URI will also include scheme and hostname.

Just as for URI resolving, the publicUri() function will automatically resolve the URI within the context of the correct module when including templates contained in other modules.

8.4.2.1.3.2 inSourceMode()

This function returns a boolean argument indicating if the module containing the template file was loaded in source mode.

8.4.2.1.3.3 conf()

See accessing config from templates.

8.4.2.1.3.4 i18n() and format()

See i18n templates integration.

8.4.2.2 Groovy

When you want to unleash greater power in the templates, you can use groovy expressions: $g{<groovy-exp>} or #g{<groovy-exp>}.
e.g. $g{"groovy "*3} prints 'groovy groovy groovy'.

 PreviousHomeNext 
8.4 Syntax reference8.4.3 Template inheritance