Block helpers are templates that wrap the content of the block. They can be used to show content in different ways depending on conditions, or they can be used to add extra functionality to the blocks content, for example, some JavaScript calculation on its DOM elements.
In the following example, we will build a simple block helper that will show content based on a Boolean condition.
To do this, we will to add the following code snippet at the end of our example.html
file:
<template name="blockHelperExample"> <div> <h1>My Block Helper</h1> {{#if this}} <p>Content goes here: {{> Template.contentBlock}}</p> {{else}} <p>Else content here: {{> Template.elseBlock}}</p> {{/if}} </div> </template>
The {{> Template.contentBlock}}
is a predefined placeholder for the block's content. The same applies for {{> Template.elseBlock}}
.
When this
(in this example, we use the template's context...