Liquid template language

Doctave supports the Liquid template language for attaching custom rendering logic within Markdown documents. Most common usage includes templating and control flow.

Note: all features of liquid may not be supported.

Templating

include

Insert the rendered content of another template within the current template.

{% include "template-name" %}

Include is most commonly used when reusing content.

capture

Capture the content inside the capture block as Markdown. Helpful when passing content to partials that needs to be interpreted as Markdown instead of a string.

               ┌── Capture the block into a variable `content`
               v
{% capture content %}
**Rich** content that supports [markdown](www.example.com).
{% endcapture content %}

You can now use the content you captured to pass it to a partial:

  Use the `content` variable you just captured ─┐ 
                                                v
{% include "_partials/callout.html" content: content %}

Control flow

if

Executes a block of code only if a certain condition is true.

{% if DOCTAVE.user_preferences.shoes == "Awesome Shoes" %}
  These shoes are awesome!
{% endif %}

If statements and control flow are most commonly used with user preferences to allow creating dynamic content.

unless

The opposite of if: executes a block of code only if a certain condition isn't met.

{% unless DOCTAVE.user_preferences.shoes == "Awesome Shoes" %}
  These shoes aren't awesome.
{% endunless %}

This would be the equivalent of doing the following:

{% if DOCTAVE.user_preferences.shoes != "Awesome Shoes" %}
  These shoes aren't awesome.
{% endif %}

elsif / else

Adds more conditions within an if or unless block.

{% if DOCTAVE.user_preferences.character == "kevin" %}
  Hey Kevin!
{% elsif DOCTAVE.user_preferences.character == "anonymous" %}
  Hey Anonymous!
{% else %}
  Hi Stranger!
{% endif %}

Was this page helpful?