# Template Documentation

This part of the documentation contains all fields that can be used in templates and a quick guide how to create templates.

# Introduction

We are using HTML &amp; CSS to typeset and layout publications. HTML (*Hypertext Markup Language*) is a markup language and the base of every website. HTML contains your contents in a structured, machine readable form. CSS (*Cascading Style* Sheets) adds styling to HTML documents, so they no longer just a wall of text.

### HTML

A basic HTML document would look like this:

<p class="callout warning">This is not a useful template and just an example how basic HTML works</p>

```html

<html>
<body>

<h1>My First Heading</h1>
<p>My first paragraph.</p>

</body>
</html> 
```

### Templates

Our templates are not pure HTML, they are written with handlebars. The templates contain HTML but also adds placeholders where your content blocks (e. g. a headline and a paragraph) will be added later. The template is used to generate the finished HTML file.

So this template:

```html

<html>
<body>

{{#each children}}
{{html}}
{{/each}}  

</body>
</html> 
```

with two content blocks inside, children could generate the HTML above.

### CSS

When we created a template, we can add CSS to style our publications. There are multiple ways to add CSS:

#### Inline CSS

<p class="callout warning">This should only be used if you only want to style one specific element.</p>

```html

<html>
<body>

<h1 style="color: red;">My First Heading</h1>
<p>My first paragraph.</p>

</body>
</html> 
```

This will result in a red headline.

#### Stylesheets

<p class="callout info">This is the preferred way to style your publications since it defines universal styling rules that will be automatically applied.</p>

Firstly, we have to add a *head* block with a link to our css file (here book.css):

```html

<html>
<head>
  <link rel="stylesheet" href="book.css">
</head>
<body>

<h1>My First Heading</h1>
<p>My first paragraph.</p>

</body>
</html> 
```

Now we will need to create this css file:

```css
h1{
color: red;
}
```

Now all level 1 headings (h1) will be rendered red.

### More Resources

This article can only give you a first impression of what HTML/CSS is. You can find a detailed guide to create templates in the next articles, but you should learn the HTML/CSS basics first.

Here is a list of good resources for learning the basics:

- [W3Schools HTML Tutorial](https://www.w3schools.com/html/)
- [W3Schools CSS Tutorial](https://www.w3schools.com/Css/)

</body></html>

# Template Syntax

Templates are mostly used to create an HTML version of your content, which then can be used to create further formats (e.g., PDF, EPUB). Our templates are based on [Handlebars](https://handlebarsjs.com/), a simple template engine.

## Print a value

To display a value (see available fields) you can use **two curly brackets**:

`<h1>Book Title: {{metadata.title}}</h1>`

You will need to use three curly brackets, if your fields contain HTML:

`<h1>Book Title with HTML: {{{metadata.title}}}</h1>`

## Conditions

You may want to hide/show fields depending on if they are empty/unset or not.

### If-Condition

Use the if condition to only do something, if the value is not null/empty:

```
{{#if metadata.subtitle}}
<h2>{{metadata.subtitle}}</h2>
{{/if}}
```

This code snippet will only create a heading if metadata.subtitle is not null/empty.

<p class="callout info">**Why should I bother using if's?** You could just use {{metadata.subtitle}} and if it's empty it will not show. But it will typically still affect spacing/etc. if you create the HTML element (e.g., an empty &lt;h2&gt;&lt;/h2&gt;)</p>

You can also add an else branch, which will be executed if the specified field is null/empty:

```
{{#if metadata.title}}
<h1>{{metadata.title}}</h1>
{{else}}
<h1>Lorem Ipsum</h1>
{{/if}}
```

This code snippet will print “Lorem Ipsum” if metadata.title is null/empty.

### Unless-Condition

If you want to show something, unless a variable is set &amp; not empty, you can use unless:

```
{{#unless metadata.title}}
<h1>Warning: Title missing!</h1>
{{/unless}}
```

## Iterate through multiple Entries

Often you will need to iterate through a list of things, e.g. authors or sections. You can use each for that:

```
<h1>Contributing Authors:</h1>

{{#each metadata.authors}}
<p>{{first_names}} {{last_names}}</p>
{{/each}}
```

This snippet will show first and last names of every author in the project.

<p class="callout warning">**Context Change**  
Note that the context changes with the use of each: You may expect we would use {{metadata.authors.first\_names}}, but we have to strip away metadata.authors since we "entered" the context when we used each.</p>

## Partials

You may want to split your template into several, reusable parts. Just create another template file (e.g. metadata\_page.hbs.html) and include it via `{{> metadata_page}}` or `{{> global_assets/metadata_page}}` if you created the template as a global asset.

# Fields to be used in templates

This section contains a list of all fields you can currently use in templates.

Notation: List&lt;Person&gt; = a list of values with the type Person,

## Project Metadata

**Prefix: `metadata.`**   
(e.g. `metadata.title` prints the book title)

<table border="1" id="bkmrk-field-type-%28string%2Fn" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 16.8057%;"></col><col style="width: 18.9511%;"></col><col style="width: 20.739%;"></col><col style="width: 43.5042%;"></col></colgroup><tbody><tr><td>**Field**  
</td><td>**Type (string/number/list/type/bool)**  
</td><td>**Optional (true/false)**  
</td><td>**Description**  
</td></tr><tr><td>title  
</td><td>string  
</td><td>**false**  
</td><td>Project title  
</td></tr><tr><td>subtitle  
</td><td>string  
</td><td>true  
</td><td>Project subtitle  
</td></tr><tr><td>authors  
</td><td>List&lt;PersonOrString&gt;  
</td><td>**false** (but may be empty)  
</td><td>List of all authors, either added to the project or to one of the (sub)sections  
</td></tr><tr><td>editors  
</td><td>List&lt;PersonOrString&gt;  
</td><td>**false** (but may be empty)  
</td><td>List of all editors, either added to the project or to one of the (sub)sections  
</td></tr><tr><td>web\_url  
</td><td>string  
</td><td>true  
</td><td>URL to a web version of this project (e.g. blog symposium)</td></tr><tr><td>identifiers  
</td><td>List&lt;Identifier&gt;  
</td><td>true  
</td><td>List of identifiers, e.g. ISBNs, DOIs, etc.  
</td></tr><tr><td>published</td><td>DetailedDate</td><td>true  
</td><td>publish date</td></tr><tr><td>languages  
</td><td>List&lt;Language&gt;  
</td><td>true  
</td><td>project language(s)  
</td></tr><tr><td><span style="color: rgb(149, 165, 166);">number\_of\_pages</span>  
</td><td><span style="color: rgb(149, 165, 166);">number</span>  
</td><td><span style="color: rgb(149, 165, 166);">true</span>  
</td><td><span style="color: rgb(149, 165, 166);">currently not used</span></td></tr><tr><td>short\_abstract  
</td><td>string  
</td><td>true  
</td><td>short abstract / content summary  
</td></tr><tr><td>long\_abstract  
</td><td>string  
</td><td>true  
</td><td>long abstract / content summary  
</td></tr><tr><td>keywords  
</td><td>List&lt;Keyword&gt;  
</td><td>true  
</td><td>List of keywords with optional gnd identifier  
</td></tr><tr><td>ddc  
</td><td>string  
</td><td>true</td><td>DDC class  
</td></tr><tr><td>license  
</td><td>License  
</td><td>true  
</td><td>License of the publication - either Creative Commons or a custom license.

Variants:

- CC0
- CC\_BY\_4
- CC\_BY\_SA\_4
- CC\_BY\_ND\_4
- CC\_BY\_NC\_4
- CC\_BY\_NC\_SA\_4
- CC\_BY\_NC\_ND\_4
- other (contains a string)

</td></tr><tr><td>series  
</td><td>string  
</td><td>true  
</td><td>Series this publication belongs to  
</td></tr><tr><td>volume  
</td><td>string  
</td><td>true  
</td><td>Volume this publication belongs to  
</td></tr><tr><td>edition  
</td><td>string  
</td><td>true  
</td><td>Edition of this publication  
</td></tr><tr><td>publisher  
</td><td>string  
</td><td>true  
</td><td>Publisher of this publication  
</td></tr></tbody></table>

#### PersonOrString

One of these variants:

- Person -&gt; type Person
- NameString -&gt; type String

#### Person

<table border="1" id="bkmrk-field-type-%28string%2Fn-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col></colgroup><tbody><tr><td>**Field**  
</td><td>**Type (string/number/list/type/bool)**  
</td><td>**Optional (true/false)**  
</td><td>**Description**  
</td></tr><tr><td>id  
</td><td>string  
</td><td>true  
</td><td>internal unique id</td></tr><tr><td>first\_names  
</td><td>string  
</td><td>true  
</td><td>one or more first names</td></tr><tr><td>last\_names  
</td><td>string  
</td><td>**false**  
</td><td>one or more last names  
</td></tr><tr><td>orcid  
</td><td>Identifier  
</td><td>true  
</td><td>ORCID (Open Researcher and Contributor ID)  
</td></tr><tr><td>gnd  
</td><td>Identifier  
</td><td>true  
</td><td>GND (Gemeinsame Normdatei)  
</td></tr><tr><td>bios  
</td><td>List&lt;Biography&gt;  
</td><td>true  
</td><td>list of biographies for this person, with specified language  
</td></tr><tr><td>ror  
</td><td>Identifier</td><td>true  
</td><td>ROR (Research Organization Registry ID)  
</td></tr></tbody></table>

#### Identifier

<table border="1" id="bkmrk-field-type-%28string%2Fn-2" style="border-collapse: collapse; width: 100%; height: 76.4px;"><colgroup><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col></colgroup><tbody><tr style="height: 46.6px;"><td style="height: 46.6px;">**Field**  
</td><td style="height: 46.6px;">**Type (string/number/list/type/bool)**  
</td><td style="height: 46.6px;">**Optional (true/false)**  
</td><td style="height: 46.6px;">**Description**  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">id  
</td><td style="height: 29.8px;">string  
</td><td style="height: 29.8px;">true  
</td><td style="height: 29.8px;">internal unique id  
</td></tr><tr><td>name  
</td><td>string  
</td><td>**false**  
</td><td>custom name of the identifier (e.g. "ebook ISBN)</td></tr><tr><td>value  
</td><td>string  
</td><td>**false** </td><td>value of the identifier (e.g. the ISBN)</td></tr><tr><td>identifier\_type  
</td><td>IdentifierType  
</td><td>**false** </td><td>Identifier Type - one of these variants:  
- DOI
- ISBN
- ISSN
- URL
- URN
- ORCID
- ROR
- GND
- Other (contains a string)

</td></tr></tbody></table>

#### Language

One of these variants:

- DE
- EN

#### Biography

<table border="1" id="bkmrk-field-type-%28string%2Fn-3" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col></colgroup><tbody><tr><td style="height: 46.6px;">**Field**  
</td><td style="height: 46.6px;">**Type (string/number/list/type/bool)**  
</td><td style="height: 46.6px;">**Optional (true/false)**  
</td><td style="height: 46.6px;">**Description**  
</td></tr><tr><td>content  
</td><td>string  
</td><td>**false**  
</td><td>the biography  
</td></tr><tr><td>lang  
</td><td>Language  
</td><td>**true** </td><td>language of the biography</td></tr></tbody></table>

#### Keyword

<table border="1" id="bkmrk-field-type-%28string%2Fn-4" style="border-collapse: collapse; width: 100%; height: 106.2px;"><colgroup><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col></colgroup><tbody><tr style="height: 46.6px;"><td style="height: 46.6px;">**Field**  
</td><td style="height: 46.6px;">**Type (string/number/list/type/bool)**  
</td><td style="height: 46.6px;">**Optional (true/false)**  
</td><td style="height: 46.6px;">**Description**  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">title  
</td><td style="height: 29.8px;">string  
</td><td style="height: 29.8px;">**false**</td><td style="height: 29.8px;">the keyword</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">gnd  
</td><td style="height: 29.8px;">Identifier  
</td><td style="height: 29.8px;">true  
</td><td style="height: 29.8px;">GND belonging to this keyword  
</td></tr></tbody></table>

#### DetailedDate


<table border="1" id="bkmrk-field-type-%28string%2Fn-5" style="border-collapse: collapse; width: 100%; height: 106.2px;"><colgroup><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col></colgroup><tbody><tr style="height: 46.6px;"><td style="height: 46.6px;">**Field**  
</td><td style="height: 46.6px;">**Type (string/number/list/type/bool)**  
</td><td style="height: 46.6px;">**Optional (true/false)**  
</td><td style="height: 46.6px;">**Description**  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">year</td><td style="height: 29.8px;">number</td><td style="height: 29.8px;">false</td><td style="height: 29.8px;">the year</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">month</td><td style="height: 29.8px;">number</td><td style="height: 29.8px;">true</td><td style="height: 29.8px;">month as number without leading zero</td></tr><tr><td>month\_leading\_zero</td><td>string</td><td>true</td><td>month as string with leading zero</td></tr><tr><td>month\_name</td><td>MonthName</td><td>true</td><td>Matches one of these variants:

- january
- february
- march
- april
- may
- june
- july
- august
- september
- october
- november
- december

</td></tr><tr><td>day</td><td>number</td><td>true</td><td>day as number without leading zero

</td></tr><tr><td>day\_leading\_zero</td><td>string</td><td>true</td><td>day as string with leading zero

</td></tr><tr><td>day\_weekday</td><td>Weekday</td><td>true</td><td>Matches one of these variants:

- monday
- tuesday
- wednesday
- thursday
- friday
- saturday
- sunday

</td></tr></tbody></table>

## Project Settings

**Prefix: `settings.`**   
(e.g. `settings.cover_image_path`)

Note: settings is an optional field

<table border="1" id="bkmrk-field-type-%28string%2Fn-6" style="border-collapse: collapse; width: 100%; height: 242.2px;"><colgroup><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col></colgroup><tbody><tr style="height: 46.6px;"><td style="height: 46.6px;">**Field**  
</td><td style="height: 46.6px;">**Type (string/number/list/type/bool)**  
</td><td style="height: 46.6px;">**Optional (true/false)**  
</td><td style="height: 46.6px;">**Description**  
</td></tr><tr style="height: 46.6px;"><td style="height: 46.6px;">toc\_enabled  
</td><td style="height: 46.6px;">bool  
</td><td style="height: 46.6px;">false  
</td><td style="height: 46.6px;">Whetether a table of contents should be shown  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">csl\_style  
</td><td style="height: 29.8px;">string  
</td><td style="height: 29.8px;">true</td><td style="height: 29.8px;">name of the enabled csl (citation style language)  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">csl\_language\_code  
</td><td style="height: 29.8px;">string  
</td><td style="height: 29.8px;">true  
</td><td style="height: 29.8px;">used language code for csl  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">metadata\_page\_additional\_html  
</td><td style="height: 29.8px;">string  
</td><td style="height: 29.8px;">true  
</td><td style="height: 29.8px;">Information to be shown on the metadata/imprint page  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">cover\_image\_path  
</td><td style="height: 29.8px;">string  
</td><td style="height: 29.8px;">true  
</td><td style="height: 29.8px;">filename of the cover image. You can include the image with `<img src="uploads/{{settings.cover_image_path}}">`  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">backcover\_image\_path  
</td><td style="height: 29.8px;">string  
</td><td style="height: 29.8px;">true  
</td><td style="height: 29.8px;">filename of the backcover image. You can include the image with `<img src="uploads/{{settings.backcover_image_path}}">`  
</td></tr></tbody></table>

## Project Contents

**`sections` is a List of Sections**.

Example to print all section titles:

```
{{#each sections}}
<h1>{{metadata.title}}</h1>
{{/each}}
```

#### Section

<table border="1" id="bkmrk-field-type-%28string%2Fn-7" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col></colgroup><tbody><tr><td style="height: 46.6px;">**Field**  
</td><td style="height: 46.6px;">**Type (string/number/list/type/bool)**  
</td><td style="height: 46.6px;">**Optional (true/false)**  
</td><td style="height: 46.6px;">**Description**  
</td></tr><tr><td>id</td><td>string</td><td>false</td><td>unique section id</td></tr><tr><td>sub\_sections</td><td>List&lt;Section&gt;</td><td>false (but can be empty)</td><td>a (nested) list of sections</td></tr><tr><td>children</td><td>List&lt;ContentBlock&gt;</td><td>false (but can be empty)</td><td>content blocks of this section</td></tr><tr><td>metadata</td><td>SectionMetadata</td><td>false</td><td>Metadata of this section</td></tr><tr><td>visible\_in\_toc</td><td>bool</td><td>false</td><td>whetether this section should be shown in the toc   
</td></tr><tr><td>endnotes</td><td>List&lt;Endnote&gt;</td><td>false (but can be empty)</td><td>list of endnotes used in this section  
</td></tr></tbody></table>

#### ContentBlock

<table border="1" id="bkmrk-field-type-%28string%2Fn-8" style="border-collapse: collapse; width: 100%; height: 88.4px;"><colgroup><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col></colgroup><tbody><tr style="height: 28.8px;"><td style="height: 46.6px;">**Field**  
</td><td style="height: 46.6px;">**Type (string/number/list/type/bool)**  
</td><td style="height: 46.6px;">**Optional (true/false)**  
</td><td style="height: 46.6px;">**Description**  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">id</td><td style="height: 29.8px;">string</td><td style="height: 29.8px;">false</td><td style="height: 29.8px;">unique content block id</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">block\_type</td><td style="height: 29.8px;">BlockType</td><td style="height: 29.8px;">false</td><td style="height: 29.8px;">BlockType variants:

- Paragraph
- Heading
- Raw
- List
- Quote
- Image

</td></tr><tr><td>html</td><td>string</td><td>false</td><td>content of this block as html

</td></tr></tbody></table>

#### SectionMetadata

<table border="1" id="bkmrk-field-type-%28string%2Fn-9" style="border-collapse: collapse; width: 100%; height: 398.8px;"><colgroup><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col></colgroup><tbody><tr style="height: 46.6px;"><td style="height: 46.6px;">**Field**  
</td><td style="height: 46.6px;">**Type (string/number/list/type/bool)**  
</td><td style="height: 46.6px;">**Optional (true/false)**  
</td><td style="height: 46.6px;">**Description**  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">title</td><td style="height: 29.8px;">string</td><td style="height: 29.8px;">false</td><td style="height: 29.8px;">title of this section</td></tr><tr style="height: 63.4px;"><td style="height: 63.4px;">toc\_title\_subtitle\_override</td><td style="height: 63.4px;">string</td><td style="height: 63.4px;">true</td><td style="height: 63.4px;">optional version of the title + subtitle for the table of contents</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">subtitle</td><td style="height: 29.8px;">string</td><td style="height: 29.8px;">true</td><td style="height: 29.8px;">subtitle of this section</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">authors</td><td style="height: 29.8px;">List&lt;PersonOrString&gt;</td><td style="height: 29.8px;">false (but can be empty)</td><td style="height: 29.8px;">authors of this section</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">editors</td><td style="height: 29.8px;">List&lt;PersonOrString&gt;</td><td style="height: 29.8px;">false (but can be empty)</td><td style="height: 29.8px;">editors of this section</td></tr><tr style="height: 46.6px;"><td style="height: 46.6px;">web\_url</td><td style="height: 46.6px;">string</td><td style="height: 46.6px;">true</td><td style="height: 46.6px;">url to web version of this section (e.g. blog post)</td></tr><tr style="height: 46.6px;"><td style="height: 46.6px;">identifiers</td><td style="height: 46.6px;">List&lt;Identifier&gt;</td><td style="height: 46.6px;">false (but can be empty)</td><td style="height: 46.6px;">identifiers of this section (e.g. chapter doi)</td></tr><tr style="height: 46.6px;"><td style="height: 46.6px;">published</td><td style="height: 46.6px;">DetailedDate</td><td style="height: 46.6px;">true</td><td style="height: 46.6px;">date the section was published</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">lang</td><td style="height: 29.8px;">Language</td><td style="height: 29.8px;">false</td><td style="height: 29.8px;">language of this section</td></tr></tbody></table>

#### Endnote

<table border="1" id="bkmrk-field-type-%28string%2Fn-10" style="border-collapse: collapse; width: 100%; height: 76.4px;"><colgroup><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col><col style="width: 25.0298%;"></col></colgroup><tbody><tr style="height: 46.6px;"><td style="height: 46.6px;">**Field**  
</td><td style="height: 46.6px;">**Type (string/number/list/type/bool)**  
</td><td style="height: 46.6px;">**Optional (true/false)**  
</td><td style="height: 46.6px;">**Description**  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">num</td><td style="height: 29.8px;">number</td><td style="height: 29.8px;">false</td><td style="height: 29.8px;">number of the endnote in this section</td></tr><tr><td>id</td><td>string</td><td>false</td><td>unique id of the endnote</td></tr><tr><td>content</td><td>string</td><td>false</td><td>formatted endnote as html</td></tr></tbody></table>

# Special Helpers (QR-Codes)

Currently, we provide a special handlebars helper that can be used in templates:

## QR-Code Helper

Syntax: `{{qrcode <content> <dark_color> <light_color>}}`

With this helper, you can create QR-Codes (as svg) with the specified content (e.g. a URL). Optionally, you can provide a dark and/or a light colour (as hex string) to be used in the QR-Code.

Examples:

`{{qrcode "https://verfassungsblog.de"}}` - Creates a simple QR-Code leading to verfassungsblog.de with black colour on white background

`{{qrcode "https://verfassungsblog.de" "#FB5074"}}` - Creates a QR-Code with pink colour on white background