DotLiquid for Designers

dumky edited this page Jul 30, 2015 · 11 revisions

DotLiquid is intended to be as compatible as possible with the original Liquid syntax. With this in mind, we don't maintain our own template syntax documentation page; we refer you to the original Liquid for designers Liquid GitHub page, but strongly recommend you review the notes below before proceeding:

http://github.com/Shopify/liquid/wiki/Liquid-for-Designers

Any (known!) differences between DotLiquid and Liquid template syntax are noted below.

Line breaks

To suppress the line break that would normally follow the end of a tag, you can use a hyphen ("-") just before closing the tag. For example:

<ul>
{% for item in user.tasks -%}
  <li>{{ item.name }}</li>
{% endfor -%}
</ul>

will result in the following output, without extra line breaks:

<ul>
  <li>Documentation</li>
  <li>Code comments</li>
</ul>

Date format strings

When using the date filter, DotLiquid supports both Ruby and .NET date format strings (but not both at the same time). By default, it will use .NET date format strings. This can be changed by setting a configuration property:

Liquid.UseRubyDateFormat = true;

.NET Format strings can be found here: http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx

Using a .NET date format string within a template: {{ SomeDateField | date:"MMMM dd, yyyy" }}

Filter and Output Casing

Liquid by default uses Ruby casing for output fields and filters such as {{ some_field | escape }}. DotLiquid uses this same convention by default, but can also be changed to use C# naming convention, in which case output fields and filters would be referenced like so {{ SomeField | Escape }}

Includes

You can include a partial template with this tag: {% include "partial_template" %}

By naming convention this will find the _partial_template.liquid file in the directory specified with:

Template.FileSystem = new LocalFileSystem(root); // root needs to be an absolute path