Custom helpers
website-generator includes some of its own helpers in addition to the built-in helpers of Handlebars.
Some of the below examples reference front matter to demonstrate their functionality but any template variable can be passed to these additional helpers.
dateformat
Formats a date string into a given format, provided that it is supported. Supported formats are:
D MMMM YYYY, e.g. 1 January 2000.
Usage
Define a date in the front matter to reference in a template.
+++
date = "2020-01-01"
+++
<p>1 January 2000.</p>
equal
Performs a strict equality check in JavaScript (===) against two values.
Supports else sections.
Usage
Without else section
<p>true is equal to true.</p>
With else section
<p>true is not equal to false.</p>
markdownify
Parses the supplied value as Markdown.
Usage
<p><strong>This is bold text.</strong></p>
isarray
Performs an array check in JavaScript using the Array.isArray method. Supports
else sections.
Usage
Define an array in the front matter to reference in a template.
+++
array = [1, 2, 3]
+++
Without else section
<p>This value is an array.</p>
With else section
<p>This value is not an array.</p>
sort
Sorts an array of JavaScript objects using a specified key.
Usage
Define an array of items in the front matter to reference in a template.
+++
object = [{ id = 1 }, { id = 2 }, { id = 3 }]
+++
With default sort order
A descending sort order is applied by default:
<ul>
<li>3</li>
<li>2</li>
<li>1</li>
</ul>
With ascending sort order
Pass ascending=true for ascending sort order:
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
stripnewlines
Removes all newlines from a string.
Usage
<p>This paragraph contains no newlines.</p>