Table of Contents

Liquid Markup Language

Liquid is the language used to build custom SandwichBoard themes. It is a small and fast template language, which is quick to learn and yet is very powerful.

Basics

There are two types of markup in liquid: Output and Tag.

Output blocks will always be replaced with the data which they reference. If your Liquid template has a menu object exposed to it, you can render the name of the menu by referencing {{ menu.name }}. Output blocks may be manipulated by Liquid filters.

Tags drive the logic of templates. They are responsible for loops and branching logic such as If / Else.

It is often necessary to access SandwichBoard-created objects like menus and restaurant locations by using their Liquid drops in Output and Tags.

Sometimes you have to use string literals, which are constructed inside single-quotes.

Example

'tobi'

Output

Here is a simple example of Output:

Hello {{ name }}
Hello {{ menu.name }}
Hello {{ 'tobi' }}

Filters

Output markup takes filters. Filters are simple methods. The first parameter is always the output of the left side of the filter. The return value of the filter will be the new left value when the next filter is run. When there are no more filters the template will receive the resulting string. This is very similar to the concept of piping in *NIX.

Hello {{ 'tobi' | upcase }}                    # => Hello TOBI
Hello tobi has {{ 'tobi' | length }} letters!  # => Hello tobi has 4 letters!
Hello {{ 'to_bi' | handle | upcase }}          # => Hello TO_BI

Some filters take more than one input value. date(input, format) for example takes both a date and format string as parameters. The first parameter, input, is passed from left to right as usual. The second parameter, format is passed after the colon immediately following the name of the function, date.

Hello {{ article.created_at | date: '%Y %H' }} # => 2009 03

Any additional parameters also come after the colon and are separated from each other with commas.

This is a hypothetical link {{ menu | link_to_menu: '_blank', 'blink' }}

Tags

Tags are for the logic in your template.

Here is a list of currently supported tags:

Global Variables

Several Liquid variables are accessible from any template or page:

Articles and events can be tagged in SandwichBoard with keywords. To limit the collections to a specific tag, simply suffix articles or events with _by_keyword.

Example

{% for article in articles_by_press %}
  ...
{% endfor %}


You can read more about Liquid at the project's official web site.