Kauri Documentation
4.3 The Kauri Runtime: modulesBook Index4.5 Forms

4.4 Templates

As most other web frameworks, Kauri has a template language, in which you will find the familiar constructs. More detailed information on templates is found here.

It is not the kind of template language like JSP, in which you can embed arbitrary (Java) code, but rather a restricted one in which you can use a limited set of constructs like loops, if's and expressions. We do reuse JSP's expression language (EL).

Kauri's template language is a standalone, reusable library not tied to any other parts of Kauri.


The template language is XML-based. Each template file has to be a well-formed XML file. The advantage of this is that the template output will always be well-formed markup (start and end tags match, proper escaping of special characters), common formatting rules are enforced (an empty script tag should have a close tag, things like that), and the output is produced as SAX-events instead of characters, allowing to connect it to other XML transformation components (such as XSLT) in an efficient way.

Template inheritance

To support a common layout across pages, we support template inheritance, inspired by Django's template language. With template inheritance, you can define a base template in which there are regions which can be overridden by child templates.

As an example, take this base template:

<?xml version="1.0"?>
<html xmlns:t="http://kauriproject.org/template">

      <t:block name="title">The title</t:block>

    <t:block name="main">Main content</t:block>

The listing below shows a template inheriting from this base template. Notice the t:inherit attribute on the root element. The content of the t:block elements will replace that of the base template. All content outside the t:block's will be ignored. This allows to add body tags etc. so that the inherited template can be viewed stand-alone too.

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns:t="http://kauriproject.org/template"

  <t:block name="title">My page</t:block>

  <t:block name="main">My interesting content</t:block>


Multiple inheritance, calling the “super” block and cross-block initialization are supported. All this is explained here.

Link translation

A module does not know on beforehand where in the URI space its resources will end up. In case it reuses REST-services from other modules, it will even less know where those will end up in the URI-space. Therefore, the template langauge has a special publicUri() function to translate from internal paths to public paths. REST-services are internally addressed using a service protocol, so a publicUri() call looks like:

<a href="publicUri('service:/main/person/john.html')">John</a>
4.3 The Kauri Runtime: modules4.5 Forms