Squidex
  • Welcome to Squidex
  • Getting Started
    • Squidex Cloud
    • Installation Instructions
      • Platforms
        • Install on Kubernetes
        • Install on AWS (Deprecated)
        • Install on AWS EC2 using Docker
        • Install on Azure
        • Install on Azure using ARM
        • Install on Google Cloud Platform (GCP)
        • Install on Docker
        • Install on Heroku
        • Install on IIS
        • Install on Render
        • Install on Vultr
      • Configuration
        • Deploying the Image Resizer Service
      • Troubleshooting and Support
        • Diagnose Runtime Issues
        • Restoring Deleted Apps
      • Install Identity (Deprecated)
      • External Identity Providers
        • Azure AD (OAuth) with Squidex
    • Contributing and Developing
      • Building
      • Developing
      • Extensions
        • Custom Rule Action
      • Contributing
      • Architecture
      • Translating
      • Squidex Docs Program
    • Roadmap
    • Quick Start Guides
      • Vue.js Blog with Squidex
      • React.js Blog with Squidex
      • Angular Blog with Squidex
  • Documentation
    • Introduction and Use Case
    • Concepts
      • Apps
      • Teams
      • Schemas
        • Field Rules
      • Content
        • Scheduled Publishing
      • Assets
        • Querying Assets
      • Localization
      • Migrations
      • Roles & Permissions
      • Rules
        • Publish an Event to Azure Queues using Rules
        • Populate Elasticsearch Index
      • Backups
      • Subscriptions
        • App Subscriptions v/s Team Subscriptions
      • Notifications
      • Dashboard
      • Workflows
    • Software Development Kits
      • TypeScript
      • .NET
        • Version v14 (and Earlier)
        • Version v15 (and Later)
      • PHP
      • Java
    • Developer Guides
      • API
        • Authentication
        • Postman
        • Queries
        • Assets
      • Automation Tools (CLI)
      • Scripting
        • Scripting Helper Methods
      • Embed Content
      • Custom Workflows
      • Custom Editors
      • Custom Sidebars
      • Preview Content
      • Rule Formatting
        • Simple
        • Script
        • Liquid
      • Tutorials
        • Building a Blog with Squidex and Next.js
  • Next
    • Squidex 3.0: API Compatibility
Powered by GitBook
On this page
  • Basic Syntax
  • Special Extensions
  • Tags
  • Filters
  • How to handle JSON

Was this helpful?

  1. Documentation
  2. Developer Guides
  3. Rule Formatting

Liquid

How to Format Rules with Liquid Templates.

PreviousScriptNextTutorials

Last updated 10 months ago

Was this helpful?

You can use liquid templates using the following syntax:

Liquid(<YOUR_SCRIPT>)

In newer versions of Squidex, the user interface has been improved and custom input fields have been introduced which allow for selection of the syntax and adds the necessary prefix automatically.

Basic Syntax

The liquid syntax is documented by Shopify at .

Special Extensions

Squidex provides special extensions.

Tags

reference

Resolves a content by ID and saves the content as a variable.

// Input


{% for id in event.data.references.iv %}
   {% reference 'ref', id %}
   Text: {{ ref.data.field1.iv }} {{ ref.data.field2.iv }} {{ ref.id }}
{% endfor %}



// Output
Text: Content1_Field1 Content1_Field2 Content1_ID
Text: Content2_Field1 Content2_Field2 Content1_ID

asset

Resolves an asset by ID and saves the asset as a variable.

// Input


{% for id in event.data.assets.iv %}
   {% asset 'ref', id %}
   Text: {{ ref.fileName }} {{ ref.id }}
{% endfor %}

// Output
Text: Asset1_FileName Asset1_ID
Text: Asset2_FileName Asset2_ID

Filters

format_date

Formats a date using a specified pattern.

{{event.timestamp | format_date: 'yyyy-MM-dd-hh-mm-ss'}}

timestamp

Returns the number of milliseconds between 1970/1/1 and a given date.

{{event.timestamp | timestamp}}

timestamp_sec

Returns the number of seconds between 1970/1/1 and a given date.

{{event.timestamp_sec | timestamp}}

escape

Escapes a value to be a valid JSON string.

{{event.user.name | escape}}

html2text

Converts a HTML string to plain text.

{{event.data.body.iv | html2text}}

markdown2text

Converts a Markdown string to plain text.

{{event.data.body.iv | markdown2text}}

md5

Calculates the MD5 hash from a given string. Use this method for hashing passwords, when backwards compatibility is important

{{event.data.password.iv | md5}}

sha256

Calculates the SHA256 hash from a given string. Use this method for hashing passwords.

{{event.data.password.iv | sha256}}

slugify

Calculates the slug of a text by removing all special characters and white spaces to create a friendly term that can be used for SEO-friendly URLs.

{{event.data.title.iv | slugify}}

trim

How to handle JSON

The template engine is not aware what kind of content you create. Therefore it cannot be optimized for JSON or other formats. If you inject strings into a JSON object or array you have to ensure that the value a valid JSON string.

The solution is to use the escapefilter for string fields:

{
    "title": "{{event.data.title.en-US | escape}}",
    "text": "{{event.data.text.en-US | escape}}",
    "date": "{{event.data.date.iv}}",
    "price": {{event.data.price}}"
}

You can omit the filter for fields that follow a specific format, as for the date field above.

The same as . Removes all white space (tabs, spaces, and newlines) from both the left and right sides of a string. This does not affect spaces between words.

https://shopify.github.io/liquid/
strip