Skip to main content

Handlebars Templates

A handlebars template is a blueprint that uses the Handlebars language to define where and how variable information can be inserted into a predetermined text structure. This allows for the creation of customizable texts that automatically update with specific data. Handlebars templates are characterized by their use of Handlebars expressions within the templates.

Handlebars is a simple templating language. It uses a handlebars template and an input object to generate output texts, in any format you like. Handlebars templates look like regular text with embedded handlebars expressions, which consist of a {{, followed by some contents, and a closing }}. When a template is executed, these expressions are replaced with values from an input object.

Purpose

The purpose of Handlebars templates is to separate the logic of data manipulation from the presentation layer, facilitating maintainability and readability. This approach enables developers to create templates that can be reused with different data, leading to more efficient code and a clearer separation of concerns within web applications.

Within the context of TEv2, converters are typically specified as (predefined, or custom) handlebars templates. The converter profile of a text conversion tool specifies the class of objects that a particular converter for that tool works on.

The converter profile for a particular text conversion tool is specified in the documentation for that tool. See, e.g., the TRRT converter profile, or the HRGT converter profile.

Examples

Here are some (simple) examples for handlebars templates that are used within the context of [TEv2]

Resolving TermRefs (which is what the TRRT does) requires the creation of a text that, in the case of the TEv2 static website, can be rendered by Docusaurus. So the handlebars template might generate, e.g., HTML, or markdown. Here is an example of the TRRT converter that is used to convert a TermRef into a markdown-link:

[___HANDLEBARS0___](___HANDLEBARS1______HANDLEBARS2___#___HANDLEBARS3______HANDLEBARS4___)

The TRRT handlebars object specifies the variables showtext, navurl, and trait (and quite a few more). This template will thus prorivide a markdown link to the location pointed to by navurl,

Handlebars template for generating a HRG entry

Human readable glossaries are created by the HRGT, which uses converters to generate entries for that glossary. The data object on which the converter works includes the data that is availble in the MRG entry of the semantic unit for which the HRG entry is to be generated.

Here is a simple handlebars template that generates a HRG entry that is a level-2 markdown section of which the title is taken from the glossaryTerm field in the MRG entry, and that contains a paragraph that contains the text that is available in the glossaryText field of that entry:

## [___HANDLEBARS0___](___HANDLEBARS1___)\n\n___HANDLEBARS2___\n\n

where \n is a newline (line break).

Notes:

  • users can click on the text generated by {{glossaryTerm}}, as it is also a link to the page that documents the semantic unit for which the HRG entry was generated.
  • {{localize navurl}} is a handlebars expression that uses the helper function localize.