Working with Liquid
Treepl has implemented the full standard Shopify Liquid library. See the External Resources below for relevant links.
Learning Liquid - Free Online Course
If you are new to Liquid, see our free online course to get up to speed: Learning Liquid for Treepl CMS.
Syntax Variations
The default syntax used throughout the system when inserting liquid property tags will use square brackets, single quotes and 'capital camel case' for the property name. See the following example:
{{this['PropertyName']}}
Although, keep in mind that all property names, including custom properties added in Custom Modules, are aliased to a single word all in lowercase (flat case) for the purpose of referencing that data via Liquid.
The 'capital camel case' used above is for readability only as liquid property tags are not case sensitive.
You can choose to use an upper or lowercase syntax here.
Furthermore, as all property names are aliased to a single 'flat case' word, you can optionally use a shorthand method for referencing your property names. Such as the example following:
{{this.PropertyName}} OR {{this.propertyname}}
Notice the removal of the square brackets and single quotes and the addition of the dot (.) separator.
The dot separator is required wherever the square bracket syntax is NOT used.
The square brackets and single quote syntax is part of the liquid syntax for scenarios where property names have spaces included. This is not required in Treepl.
Empty Values (null and nil)
Often scenarios arise where properties will have no value (empty), or are not present in the Liquid output and you may want to check for this condition in your Liquid code.
In Treepl's .NET implementation of Liquid, null
is used as a special value when a value is empty or a property is not present - both conditions will resolve to a null
result. As opposed to the Shopify's Ruby implementation using nil
.
Therefore, a reliable way to check for all empty or not present conditions can be achieved as per the following example, where we are rendering something if the property is NOT equal to (!=
) null
(or an empty value):
{% if this['PropertyName'] != null %}
// Render something here
{% endif %}
For more info on null/nil
and empty values, see the External Resources below for relevant links.
Related Articles
- Liquid Objects & Usage
Liquid Filters
Liquid Filters allow you to modify the output of a Liquid object, whether that's adding something to it, removing something from it, executing a calculation, creating an array, or a wide variety of other powerful functions. - Liquid Objects & Usage
{{ this }} object
This Liquid object is globally accessible in every liquid template or layout and outputs specific... - Liquid Objects & Usage
{{ request }} object
This Liquid object is globally accessible in every liquid template or layout and outputs various... - Liquid Objects & Usage
{{ liquidContext }} object
This Liquid object is globally accessible in every liquid template or layout and outputs a... - Liquid Objects & Usage
{{ siteglobals }}
This liquid object will output any custom configure Site Information data (found in the Admin's main menu under 'Settings' > 'Site Information'). - Liquid Objects & Usage
{{ member }} object
This liquid object will output the Member's details of whom submitted a Form. You can... - Liquid Objects & Usage
{{ workflow }} object
This liquid object will output the Workflow details of a submitted Form. You can use... - Learning Liquid
Part 1: Introduction to Liquid
This free online course covers every aspect of using the Liquid templating language in Treepl CMS - from the very basics right through to advanced implementations.
You’re welcome. - Learning Liquid
Part 2: Liquid in Treepl CMS
In this part of the course we’ll explore how Liquid is implemented in treepl CMS and the overall concepts on using it to harness your website data. - Learning Liquid
Part 3: Using Liquid Filters
In this part of the course we’ll explore using Liquid Filters to transform and manipulate the display of your Treepl CMS website data. - Learning Liquid
Part 4: Advanced Liquid Tags - Liquid Components
domain_settings
This module component retrieves settings associated with the current domain, or optionally from another specified domain configured in the site instance. - Liquid Components
json
This component parses JSON data for use in Liquid, either from a remote source, a local file, or string. - Extras
Migrating from Liquid 2.0 to 3.0
This article describes differences and possible required actions for migrating from the Liquid rendering engine v2.0 to v3.0.
External Resources
Please let us know if you have any other contributions or know of any helpful resources you'd like to see added here.
Questions?
We are always happy to help with any questions you may have.
Visit the Treepl Forum for community support and to search previously asked questions or send us a message at support@treepl.co and we will consult you as soon as possible.