Render Tag Content

Custom tags can have content template and can be nested. This article describes how to implement custom tags that consists of a begin tag, an end tag, and template content between them.

Render Tag Content

We’ll start with a simple tag wrap which wraps its content into a <div class="wrapper"></div> element:

1
2
3
{% wrap %}
{{ "hello world!" | capitalize }}
{% endwrap %}

Expected output:

1
2
3
<div class='wrapper'>
Hello world!
</div>

Firstly, [register][register-tags] a tag with name wrap and parse the content into this.tpls. Here in parse(tagToken, remainTokens),

  • tagToken is current token `