Don't Repeat Yourself

Define templates when you need to reuse the same layout.Suppose you are have to display multiple elements like the following: Name: JohnTitle: Software EngineerCurrent Project: BBRTeam: Team A Name: SathishTitle: Software EngineerCurrent Project: BBRTeam: Team A


Instead of copy and pasting, define a template in a separate file. Znai uses the FreeMarker template engine. **Name**: ${name} **Title**: ${title} **Current Project**: BBR **Team**: Team A Insert your template using the fenced block syntax. The content inside the fenced block is treated as key/values. ```template templates/ name: Sathish title: Software Engineer ``` The result is rendered below: Name: SathishTitle: Software EngineerCurrent Project: BBRTeam: Team A


Consider inlined templates if you don't need to pass a lot of parameter text to the template. :include-template: templates/ {name: "Arg Name", description: "Description of the argument"} :include-template: templates/ {name: "Other Name", optional: true, description: "Yet another description of the argument"} templates/ ```columns {left: {portion: 3, align: "right"}, border: true} left: **${name}** <#if optional??> \ *optional* </#if> right: ${description} ``` Arg Name Description of the argument Other Name optional Yet another description of the argument

External Parameters

Templates can get parameters from an external file. The file can be either manually created or generated by a script or test.Consider an external JSON file... { "name": "specified name", "code": "class CodeSnippet {\n ...\n}", "description": "generated description" } ...and a template like the following: `````columns {left: {align: "right", portion: 3}, border: true} left: ${name} right: ${description} ```java ${code} ``` ````` You can include a template in your page and make use of parameters from the file: :include-template: templates/ {paramsPath: "artifacts/generated-values.json"} specified name generated description java class CodeSnippet { ... }


You can loop over a list of parameters using FreeMarker loopConsider an external file... {"names": [ {"name": "Name 1", "description": "Description 1"}, {"name": "Name 2", "description": "Description 2", "optional": "true"}, {"name": "Name 3", "description": "Description 3"} ]} ...and this template: <#list names as n> ```columns {left: {portion: 3, align: "right"}, border: true} left: **${}** <#if n.optional??> \ *optional* </#if> right: ${n.description} ``` </#list> :include-template: templates/ {paramsPath: "artifacts/names.json"} Name 1 Description 1 Name 2 optional Description 2 Name 3 Description 3