0%

Liquid Syntax Overview ID: DBT-TPL-LS

Marketpath CMS templates utilize a templating language similar to the popular handlebars templating language. This language is based off of the Liquid framework originally created by Shopify and later translated and extended across numerous languages and applications. The Marketpath version of Liquid includes several key differences from the original Liquid markup, as well as numerous additional methods and objects.

Liquid is a safe templating language that enables developers to load dynamic content in their markup. Liquid code is comprised of objects, filters, and methods.

Objects

Objects contain all of the content used while rendering pages. An object may be any one of the following types as both a singular entity or a collection of entities.

  • articles
  • blogs & blog posts
  • calendars & calendar entries
  • datastores & datastore items
  • documents
  • error pages
  • folders
  • forms
  • galleries & gallery items
  • images
  • javascript
  • menus & menu items
  • pages
  • site
  • snippets
  • tags
  • templates

Objects also include the following types that aren't edited directly in the Management UI.

  • client
  • cookies
  • headers
  • permissions
  • request
  • session
  • user

In your template objects are output using the double squiggle brackets {{ }}. You can output any object directly to the page using the following syntax.

{{ object_name }}

Some objects may not display anything when output directly to the page, while others may display formatted content using default built-in object templates.

In most cases object properties may be accessed using either notations below.

{{ object.property }}

{{ object['property'] }}

Here are some other examples of common entity properties.

{{ entity.object_type }}
{{ entity.guid }}
{{ entity.title }}

For some objects, the object['property'] syntax is required (for example, request.query_params and request.cookies). Additionally the object[‘property’] notation enables you to supply a variable to dynamically access properties. An example of this is below.

{% assign var properties = [“object_type”, “guid”, “title” ] %}
{% for prop in properties %}
    {{ entity[prop] }}
{% endfor %}

Often, objects reference other objects so the dot notation can be more than one level. The example below shows an entity with a custom field named hotel. That custom field contains an image field named primary_image and the image has the primary field path.

{{ entity.hotel.primary_image.path }}

There are an unlimited number of ways for you to build your site and extend base objects. The dot notation of Liquid makes it quite easy to access all of your content. Every object in Marketpath CMS is defined in the documentation section of the help site.

Filters

Filters may be used to modify the output of objects before being stored in a variable or output to the page. Filters are used inside object tags and are separated by the pipe character |.

{{ entity.title | capitalize }}

Multiple filters may be applied to an object at the same time and are processed in the same order that they appear in the markup. In the example below, we output the title of the page without the “a” character and capitalize the result.

{{ entity.title | remove:"a" | capitalize }}

Types of Filters

  • String Filters - Use string filters to manipulate strings.
  • Number Filters - Use number filters to convert, manipulate, and display numbers.
  • Date Filters - Use date filters to convert, manipulate, and display dates.
  • List Filters - Use list filters to create, manipulate, and display lists.
  • Security Filters - Use security filters to encrypt and decrypt strings.

All Marketpath CMS filters for Liquid can be found on the Liquid filters page of the help site documentation.

Methods

Methods are the mechanism by which templates are able to execute logic while rendering a page. All methods start with {% and end with %}, and the commands between those characters determine how the template is processed. The following sets a variable named custom_field. 

{% assign var custom_field = “hello world” %}

Here's a sample method that loads a snippet named "Primary CTA" and assigns it to the variable my_article.

{% snippet assign my_article = "Primary CTA" %}

Here's another example that loads a list of articles with the tag "Healthcare" and assigns the resulting collection of articles to a variable named healthcare_articles

{% articles assign healthcare_articles = tag:"Healthcare" %}

Some methods are used to control what is or isn't output as part of the page (such as conditionals, comments, and includes). Some methods are used to store or modify information in objects. Some methods are used for repetition. And some methods are just shortcuts intended to make your job easier as a template developer.

Methods do not output markup on the page with the exception of the include method, which is used to include partial templates, and the output_to_template directive within a method.

{% image output_to_template = "some image" %}


Feedback?

Please fill out the form below with your feedback or any questions you may have after working through the "Liquid Syntax Overview" lesson.

Your Name
Email 
Feedback / Questions