Skip to content
Other versions

Loading…

Creating Text templates

Register the Metadata group definition at Administration > Metadata.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE property-groups PUBLIC "-//OpenKM//DTD Property Groups 2.1//EN"
"http://www.openkm.com/dtd/property-groups-2.1.dtd">
<property-groups>
<property-group label="Sample Template" name="okg:tpl">
<input label="Name" name="okp:tpl.name"/>
<input label="Birth Date" name="okp:tpl.birth_date" type="date" />
<select label="Language" name="okp:tpl.language" type="simple">
<option label="Java" value="java"/>
<option label="Python" value="python"/>
<option label="PHP" value="php" />
</select>
</property-group>
</property-groups>

In order to make a relation between the template form field and the property group, you have to name them following a naming convention: replace “:” and “.” with “_”. Here you can see some example conversions:

Metadata field name Template field name Template field value
okp:tpl.name okp_tpl_name ${okp_tpl_name!}
okp:tpl.birth_date okp_tpl_birth_date ${okp_tpl_birth_date!?string(“yyyy-MM-dd”)}
okp:tpl.language okp_tpl_language ${okp_tpl_language!}

For this example we will create an HTML template. This is the source code:

<html>
<body>
<h1>Sample template</h1>
<table>
<tr>
<td><b>Name</b></td>
<td>${okp_tpl_name!}</td>
</tr>
<tr>
<td><b>Birth Date</b></td>
<td>${okp_tpl_birth_date!}</td>
</tr>
<tr>
<td><b>Language</b></td>
<td>${okp_tpl_language!}</td>
</tr>
</table>
</body>
</html>

The tags ${okp_tpl_name!}, ${okp_tpl_birth_date!} and ${okp_tpl_language!} will be replaced by the user input values. An error will occur and abort the template processing if you try to access a missing variable, but the ! operator handles this situation. In addition, you can put a default value in case of a mission one with this expression:

${missing_value!"The default one"}

The result is a PDF conversion of the HTML template with the client input requested by OpenKM.  

</property-groups>

OpenKM uses FreeMarker, so you can take advantage of the FreeMarker formatting flexibilities. For example you can set date format by this way:

${okp_tpl_birth_date?string("yyyy-MM-dd")}

Learn more about FreeMarker formatting at: Built-in Reference.  

  • Upload tpl.html file at /okm:templates with the contents described before.
  • Register metadata definition okg:tpl at Administration > Metadata 
  • Enable metadata from profiles at Administration > Profiles 
  • Add metadata group okg:tpl to tpl.html file.