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

Definition

Instead of copy and pasting, define a template in a separate file. Znai uses the http://freemarker.org 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/job.md name: Sathish title: Software Engineer ``` The result is rendered below: Name: SathishTitle: Software EngineerCurrent Project: BBRTeam: Team A

Inlined

Consider inlined templates if you don't need to pass a lot of parameter text to the template. :include-template: templates/arg-definition.md {name: "Arg Name", description: "Description of the argument"} :include-template: templates/arg-definition.md {name: "Other Name", optional: true, description: "Yet another description of the argument"} templates/arg-definition.md ```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/test-artifact.md {paramsPath: "artifacts/generated-values.json"} specified name generated description java class CodeSnippet { ... }

Loops

You can loop over a list of parameters using http://freemarker.org/docs/ref_directive_list.html 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: **${n.name}** <#if n.optional??> \ *optional* </#if> right: ${n.description} ``` </#list> :include-template: templates/multiple-arg-definition.md {paramsPath: "artifacts/names.json"} Name 1 Description 1 Name 2 optional Description 2 Name 3 Description 3