Template rendering is the process of generating a file similar to template’s content but where variables have been replaced with actual values. These values come from settings or parameters.
ComodIT uses FreeMarker as template engine, here is an example of template’s content:
<html>
<head>
<title>Simple Web Page</title>
</head>
<body>
<p>Hello world !</p>
<p>Setting key: simple_web_page</p>
<p>Setting value: ${simple_web_page}</p>
<ul>
<#list list_setting as l>
<li>${l}</li>
</#list>
</ul>
<p>Struct a: ${struct_setting.a}</p>
<p>Struct b: ${struct_setting.b}</p>
</body>
</html>
In this example, the template contains 3 variables:
Given above variable values, rendered template will look like this:
<html>
<head>
<title>Simple Web Page</title>
</head>
<body>
<p>Hello world !</p>
<p>Setting key: simple_web_page</p>
<p>Setting value: Hello</p>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
<p>Struct a: a value</p>
<p>Struct b: b value</p>
</body>
</html>
Depending on template container (application, distribution or platform), different settings are used for rendering. For example, when rendering a distribution’s file, values for variables are looked-up in distribution’s parameters, distribution’s settings, organization’s settings, environment’s settings, host’s settings and finally distribution context’s settings.
Of course, several settings may define different values for the same variable. Priorities have therefore been defined, the setting having the highest priority assigning its value to the variable. Let x < y denote the fact that x has a lower priority than y, then priorities are defined as follows:
where:
A variable having a name starting with an underscore (‘_’) is a special variable injected by ComodIT called private variable. Note that it is not possible to create a parameter or a setting targeting this kind of variable. It is therefore impossible to override the values injected by ComodIT. Again, depending on which kind of template is rendered, different private variables may be available.
Global private variables:
Distribution private variables:
Platform private variables:
Application private variables:
Distribution context private variables:
Platform context private variables:
Application context private variables:
Methods are used to transform on-the-fly variable values. For example, let a method f and a variable v be defined, the result of applying f to v can be displayed in a rendering with the following sentence in your template:
${f(v)}
Currently, ComodIT provides a single method _hash which hashes an input string. An optional second argument provides the hash algorithm to use (by default, “MD5” is used), this argument can take any of the values supported by Java’s MessageDigest.getInstance for instance MD5, SHA-1, SHA-256, etc. The output string is the hexadecimal representation of generated bytes.
For example, in order to display the content of variable v hashed with SHA-1 algorithm, you should insert the following sentence in your template:
${_hash(v,"SHA-1")}
2016 © ComodIT. All Rights Reserved. Privacy Policy | Terms of Service