Snippets
Sometimes you want to repeat a certain element, or you want to create your own element. Snippets allow you to do exactly that.
Snippet files need to be placed in the snippets
folder at the root of
your hyperbook beside the glossary and book folders.
Examples
Example 1: Block
Here is a simple example of a snippet for using a protect element with the same password and id across your hyperbook.
The snippet located in snippets/password.md.hbs
:
The markdown you need to place in your hyperbook:
The result:
😃
Example 2: Block with Parameter
You can also pass parameters to your snippet to make them dynamic. For example our password snippet from above allows to pass a hint parameter. If the hint parameter is true, a alert element will be shown.
Hyperbook is the password.
Example 3: Inline
We are ten smilies: 😃 😃 😃 😃 😃 😃 😃 😃 😃 😃
Parameters
You can use the parameters by using curly brackets and the name of the parameter.
Three curly brackets will give you the raw content.
Two curly brackets will give the HTML-escaped content.
Content
If your snippet spans across multiple lines, you can use the content parameter to use those. See Example 1.
You need to use three curly brackets for the content parameter.
Helpers
You can use the following helpers in your snippets
if
You can use the if helper to conditionally render a block.
unless
You can use the unless helper as the inverse of the if helper. Its block will be rendered if the expression returns a falsy value.
times
You can use the times helper to repeat block.
file
You can use the file helper to include the content of a file.
You can also only use a few lines of the file.
And you can define an ellipsis.
base64
You can use the bae64 helper to embedded media, even from external folders.
This works best in conjunction with the image block:
concat
Hi there
camelcase
thisIsATest
pascalcase
ThisIsATest
dashcase
This-is-a-test
lowercase
this is a test
uppercase
THIS IS A TEST
replace
Give me Apple Banana
replaceAll
Give me Apple Apple