# Filters
A filter is a Ruby method that takes one or more parameters and returns a value. Parameters are passed to filters by position: the first parameter is the expression that precedes the pipe character, and additional parameters can be passed using the name: arg1, arg2
syntax.
Output markup can take filters, which modify the result of the output statement. You can invoke filters by following the output statement's main expression with:
- A pipe character (
|
) - The name of the filter
- Optionally, a colon (
:
) and a comma-separated list of additional parameters to the filter. Each additional parameter must be a valid expression, and each filter predefines the parameters it accepts and the order in which they must be passed.
Filters can also be chained together by adding additional filter statements (starting with another pipe character). The output of the previous filter will be the input for the next one.
Hello {{ 'tobi' | upcase }}
Hello tobi has {{ 'tobi' | size }} letters!
Hello {{ '*tobi*' | textilize | upcase }}
Hello {{ 'now' | date: "%Y %h" }}
# Basics
# Append
Adds a string e.g. {{ 'foo' | append:'bar' }} #=> 'foobar'
# Capitalize
Capitalizes the word in the input sentence.
# Ceiling
Rounds up a decimal number to the next integer, e.g. {{ 4.6 | ceil }} #=> 5
# Date
Formats a date (syntax reference (opens new window))
# Default
Returns the given variable unless it is null or empty string, then it returns the given value, e.g. {{ undefined_variable | default: "Default value" }} #=> "Default value"
# Divided by
Integer division e.g. {{ 10 | divided_by:3 }} #=> 3
# Downcase
Converts an input string to lowercase.
# Escape
HTML escape a string.
# Escape once
Returns an escaped version of html without affecting existing escape entities.
# First
Gets the first element of the passed array.
# Floor
Rounds a decimal number down to the nearest integer, e.g. {{ 4.6 | floor }} #=> 4
# Format date
Formats a date with the site's localization, uses the same syntax as date
.
# Join
Joins array elements with a certain character between them.
# Last
Gets the last element of the passed array.
# Lstrip
Removes all whitespace from the beginning of a string.
# Map
Maps/collects an array into a given property.
# Minus
Subtraction e.g. {{ 4 | minus:2 }} #=> 2
# Modulo
Modulo e.g. {{ 3 | modulo:2 }} #=> 1
# Newline to br
Replaces each newline (\n) with HTML space.
# Plus
Addition e.g. {{ '1' | plus:'1' }} #=> 2
, {{ 1 | plus:1 }} #=> 2
# Prepend
Prepends a string e.g. {{ 'bar' | prepend:'foo' }} #=> 'foobar'
# Remove
Removes all occurrences e.g. {{ 'foobarfoobar' | remove:'foo' }} #=> 'barbar'
# Remove first
Removes the first occurrence e.g. {{ 'barbar' | remove_first:'bar' }} #=> 'bar'
# Replace
Replaces all occurrences e.g. {{ 'foofoo' | replace:'foo','bar' }} #=> 'barbar'
# Replace first
Replaces the first occurrence e.g. {{ 'barbar' | replace_first:'bar','foo' }} #=> 'foobar'
# Reverse
Reverses the given array.
# Round
Rounds to the nearest integer or to the specified number of decimals e.g. {{ 4.5612 | round: 2 }} #=> 4.56
# Rstrip
Removes all whitespace from the end of a string
# Script tag
Generates the HTML <script>
tag for a JavaScript template, taking as parameters the URL and attributes of the form attr: 'value'
, e.g. {{ 'my-js-url' | script_tag: async: 'async', defer: 'defer' }}
=> <script src='my-js-url' type='text/javascript' async='async' defer='defer'></script>
# Size
Returns the size of an array or string
# Slice
Splits a string. Takes an offset and a length, e.g. {{ "hello" | slice: -3, 3 }} #=> llo
# Sort
Sorts array elements
# Split
Splits a string on a matching pattern e.g. {{ "a~b" | split:"~" }} #=> ['a','b']
# Times
Multiplies e.g {{ 5 | times:4 }} #=> 20
# Truncate
Restricts a string to x characters. Also accepts a second parameter that will be appended to the string e.g. {{ 'foobarfoobar' | truncate: 5, '.' }} #=> 'foob.'
# Truncatewords
Restricts a string to x words
# Uniq
Removes duplicate elements from an array, optionally using a given property to check for uniqueness.
# Upcase
Converts an input string to uppercase
# URL encode
URL-encodes a string
# Commerce
These are the liquid filters that alter values related to Commerce.
# Format currency
Adds currency format to a value. e.g. {{ 4 | format_currency }} => $4
{{ 1890.5123 | format_currency: unit: '¥', separator: ',', delimiter: '.', precision: 3 }} = ¥1.890,512
Important
This filter determines the currency format and takes precedence over any other currency configuration.
If you don't specify currency parameters with the currency filter, Modyo uses the realm's payment configuration.
If the site doesn't have an associated realm and you don't specify parameters, the predefined format of the site's language will be applied.
Parameters:
- unit - currency symbol.
- separator - decimal separator.
- delimiter - thousands separator.
- precision - number of decimal digits.
# Content
These are the liquid filters that alter values related to the Content module in Modyo Platform.
# Asset image
Returns the tags of an image using its uuid from the File Manager. e.g. {{ uuid | asset_image }}
# Asset link
Returns the URL of an image using its uuid from the File Manager. e.g. {{ uuid | asset_link: 'This is a link for the asset' }}
# Asset URL by UUID
Returns the URL of an image using its uuid from the File Manager. e.g. {{ uuid | asset_url_by_uuid }}
# Asset video
Returns the tags of a video using its uuid from the File Manager. e.g. {{ uuid | asset_video: 350, 300 }}
Parameters:
- uuid (String) — asset uuid
- width (Integer) (default: 300) — width
- height (Integer) (default: 200) — height
# By category
Returns a list of Entries that belong to the selected Category. e.g. {% assign filtered_entries = entries | by_category: 'category2,category1,category3' %}
Parameters:
- entries (ArrayEntry) — array with entries
- list (String) (default: '') — String with comma-separated categories.
# By lang
Returns a list of Entries that belong to a selected language. e.g. {% assign entries = widget.entries | locale: 'es,en,pt' %} => entries
Parameters:
- entries (ArrayEntry) — array with entries
- locale (String) (default: '') — String with comma-separated languages.
# By slug
Returns a list of Entries that belong to a selected slug. e.g. {% assign filtered_entries = entries | by_slug: 'slug2,slug1,slug' %}
Parameters:
- entries (ArrayEntry) — array with entries
- slug (String) (default: '') — Comma-separated slugs.
# By tag
Returns a list of Entries that belong to a selected tag. e.g. {% assign entries = widget.entries | by_tag: 'tag2,tag1,tag3' %} => entries
Parameters:
- entries (ArrayEntry) — array with entries
- locale (String) (default: '') — String with comma-separated tags.
# By type
Returns a list of Entries that belong to a selected Content Type. e.g. {% assign filtered_entries = entries | by_type: 'type2,type1,type3' %}
Parameters:
- entries (ArrayEntry) — array with entries
- locale (String) (default: '') — String with comma-separated content types.
# Filter By
Returns a list of Entries that match a filter. e.g. {% assign entries = widget.entries | filter_by: field: 'name', eq: 'entry3Cat3' %}
Parameters:
- entries (ArrayEntry) — array with entries
- opts (Hash) (default: {}) — hash with field and eq as value
# Filter By Query String
Returns a list of Entries that match a query. You can use logical operators, various meta fields, URLs, or Liquid tags.
Operators:
- gt, lt, in, all, nin
Fields:
- meta.category meta.category_slug meta.category_name meta.uuid meta.name meta.created_at meta.updated_at meta.published_at meta.unpublished_at meta.slug meta.tag
Url examples:
- https://company.site.com/testsite?meta.category_slug=category3
- https://company.site.com/testsite?meta.tag=tag_name
- https://company.site.com/testsite?meta.tag[in][]=tag1_name&meta.tag[in][]=tag2_name
- https://company.site.com/testsite?meta.created_at=1987-11-19T13:13:13
e.g. {% assign entries = widget.entries | filter_by_query_string %}
Parameters:
- entries (ArrayEntry) — array with entries
# From Published Date
Returns a list of Entries that have a publication date more recent than the limit. e.g. {% assign entries = widgets.entries | from_published_date: date %}
Parameters:
- entries (ArrayEntry) — array with entries
- date (Datetime)(default: Time.zone.now) — limit date
# Limit
Limits the number of results. e.g. {{ entries | limit: 1 }}
Parameters:
- object(Array) — array
- limit (Integer)(default: 1) — result limit
# Paginated
Separates the results into pages. e.g. {{ objects | paginated: 10, 2 }}
Parameters:
- object(Array) — array
- per_page (Integer) (default: 10) — objects per page
- page (Integer) (default: 1) — page number to display
# Sort By
Returns an array with entries sorted by a field e.g. {% assign entries = widgets.entries | sort_by: 'name', 'asc' %}
Parameters:
- entries (ArrayEntry) — array with entries
- attribute (String) — field by which you want to sort
- order (String) - asc (ascending) or desc (descending)
# To Published Date
Returns a list of Entries that have a publication date older than the limit. e.g. {% assign entries = widgets.entries | to_published_date: date %}
Parameters:
- entries (ArrayEntry) — array with entries
- date (Datetime)(default: Time.zone.now) — limit date
# Crypto
These Liquid filters alter values related to Cryptography.
# Base64 Decode
Returns the Base64-decoded value of a string (e.g. {% 'Hello world' | base64_encode %} # => 'SGVsbG8gd29ybGQ='
).
# Base64 Encode
Returns the Base64-encoded value of a string (e.g. {% 'SGVsbG8gd29ybGQ=' | base64_decode %} # => 'Hello world'
).
# HMAC SHA1
Returns the SHA-1 hash using a message authentication code (HMAC) of a string (e.g. {% 'Hello world' | hmac_sha1: 'key' %} # => '2a73959742baf046e6e2e27e5ee94bcff0af31b1'
).
# HMAC SHA256
Returns the SHA-256 hash using a message authentication code (HMAC) of a string (e.g. {% 'Hello world' | hmac_sha256: 'key' %} # => 'a82b2e160edaf92a6589dc11160d2a10c04449840a58717db308c1ee3512b039'
).
# MD5
Returns the MD5 hash of a string (e.g. {% 'Hello world' | md5 %} # => '3e25960a79dbc69b674cd4ec67a72c62'
).
# SHA1
Returns the SHA-1 hash of a string (e.g. {% 'Hello world' | sha1 %} # => '7b502c3a1f48c8609ae212cdfb639dee39673f5e'
).
# SHA 256
Returns the SHA-256 hash of a string (e.g. {% 'Hello world' | sha256 %} # => '64ec88ca00b268e5ba1a35678a1b5316d212f4f366b2477232534a8aeca37f3c'
).
# CSS
These Liquid filters alter CSS-related values in Modyo Platform.
# Brighten
Adds brightness to a color (e.g. {{ '#00ff00' | brighten: 15 }} #=> '#26ff26'
).
# Darken
Reduces the brightness of a color (e.g. {{ '#00ff00' | darken: 15 }} #=> '#00b300'
).
# Desaturate
Desaturates a color (e.g. {{ '#00ff00' | desaturate: 15 }} #=> '#13ec13'
).
# Grayscale
Converts a color to grayscale (e.g. {{ '#00ff00' | grayscale }} #=> '#808080'
).
# Lighten
Lightens a color (e.g. {{ '#00ff00' | lighten: 15 }} #=> '#4dff4d'
).
# Opacity
Modifies the opacity of a color (e.g. {{ '#00ff00' | opacity: 0.5 }} #=> 'rgba(0, 255, 0, 0.5)'
).
# RGB
Transforms a color to its RGB equivalent (e.g. {{ '#00ff00' | rgb }} #=> 'rgb(0, 255, 0)'
).
# Saturate
Saturates a color (e.g. {{ '#00ff00' | saturate: 15 }} #=> '#00ff00'
).
# Spin
Rotates a color in degrees clockwise (e.g. {{ '#00ff00' | spin: 15 }} #=> 'rgba(0, 255, 0, 0.5)'
).
# Location
These Liquid filters alter values related to Geolocation in Modyo Platform.
# Dynamic Map
Returns a dynamic Google Maps map (e.g. {{ locations | dynamic_map: '600x300', 'true', 'roadmap', true}}
).
Parameters
locations
(ArrayHash) — Array of hashes with latitude and longitude points.size
(String) (default: '600x300') — Map size in pixels.zoom
(String) (default: 10) — Zoom level for the map.type
(String) (default: 'roadmap') — Map type.icon
(String) (default: '') — Map icon.controls
(String) (default: true) — Navigation controls for the map.
# Static Map
Returns a static Google Maps map (e.g. {{ locations | static_map: '600x300', 'true', 'roadmap'}}
).
Parameters
locations
(ArrayHash) — Array of hashes with latitude and longitude points.size
(String) (default: '600x300') — Map size in pixels.zoom
(String) (default: 10) — Zoom level for the map.type
(String) (default: 'roadmap') — Map type.icon
(String) (default: '') — Map icon.
# Menu Items
These Liquid filters alter values related to menu items in Modyo Platform.
# Active Page
Determines if a URL item is active. Returns 'active' when active (e.g. {{ 'company.modyo.com/jobs' | active_page: 'company.modyo.com/jobs' }} #=> 'active'
).
# Item Rel
Returns 'noopener noreferrer' if a link is "_blank" (e.g. {{ '_blank' | item_rel }} #=> 'noopener noreferrer'
).
# Resolve URL
Resolves the URL from a path and base URL (e.g. {{ 'dynamic_bank' | resolve_url: 'company.modyo.com' }} #=> 'company.modyo.com/dynamic_bank'
).
# Visible Items
Returns a list of visible items in a list of items (e.g. {{ items | visible_items }}
).
# Origination
These are the liquid filters that alter values related to originations in Modyo Platform.
# By UID
Returns the Origination with the selected UID. e.g. {% assign my_origination = site.originations | by_uid: 'my-origination' %}
Parameters:
- originations (ArrayOrigination) - array with originations
- uid (String) - Origination UID
# Site
These Liquid filters alter values related to Sites in Modyo Platform.
# Asset image Tag
Generates the HTML tag of an image (e.g. {{ asset | asset_image_tag: 'original' }}
).
# Asset Thumbnail Link Tag
Generates the HTML thumbnail tag of an image (e.g. {{ asset | asset_thumbnail_link_tag: 'class', 'target' }}
).
Parameters
asset
(Asset) — Asset-type object.classes
(String) (default: '') — Additional HTML classes (optional).target
(String) (default: '') — Additional HTML targets (optional).
# Asset URL
Generates the URL of an Asset-type object (e.g. {{ asset | asset_url: 'original' }}
).
# Audio Player
Generates the URL of an Audio-type object (e.g. {{ audio1 | audio_player }}
).
# Bar Code
Generates the URL of a barcode (e.g. {{ value | bar_code: 320, 320 }}
).
Parameters
value
(String) — Barcode value.width
(Integer) (default: 100) — Width.height
(Integer) (default: 100) — Height.
# Button To
Generates a button (e.g. {{ 'Hello World' | button_to: 'http://www.google.com' }}
).
# Cookie Value
Returns the value of a cookie (e.g. {{ 32 | cookie_value }}
).
# Embedded Video
Returns the URL of an embedded video (e.g. {{ movie2 | embedded_video }}
).
# Escape JS
Prevents JavaScript code interpretation (e.g. {{ '<script>alert("hello world");</script>' | escape_js }}
).
# Format Date
Translates a date to another format (e.g. {{ time | format_date: '%e %b, %Y' }}
).
Parameters
time
(DateTime) — Date.format_date
(String) (default: '') — The new format for the date.
# Format DateTime
Translates a date to DateTime format (e.g. {{ time | format_datetime }}
).
# Format Short Date
Translates a date to a reduced format (dd-mm-yyyy) (e.g. {{ time | format_short_date }}
).
# Link To
Adds an anchor link tag (e.g. {{ 'Hello World' | link_to: 'http://www.google.com', 'this is my alt', 'small', '_blank' }}
).
Parameters
text
(String) (default: '') — Link text.link
(String) (default: '/') — Link URL.alt
(String) (default: '') — Alternative text for the link.class
(String) (default: '') — CSS class for the link.target
(String) (default: '') — Target for the link.
# Notifications
Shows the flash message variable (e.g. {{ 'alert-error' | notifications }}
).
# Primary button to
Generates a primary type button (e.g. {{ 'Hello World' | primary_button_to: 'http://www.google.com', 'large' }}
).
Parameters
text
(String) (default: '') — Link text.link
(String) (default: '/') — Link URL.size
(String) (default: 'large') — Size for the link.
# QR Code
Generates a QR code (e.g. {{ value | qr_code: 4, 320, 320 }}
).
Parameters
value
(String) (default: '') — QR value.qr_size
(Integer) (default: 4) — QR size.width
(Integer) (default: 100) — QR width.height
(Integer) (default: 100) — QR height.
# Sanitize HTML
Sanitizes HTML tags from a String (e.g. {{ '<script>Hello World</script>' | sanitize }} #=> 'Hello World'
).
# Script tag
Adds a script tag (e.g. {{ 'test-script' | script_tag }}
).
# Search Box
Adds a search field (e.g. {{ 'testsite' | search_box }}
).
# Strftime
Converts a datetime to String format (e.g. {{ time | strftime: '%m/%d/%y' }}
).
# Strip tag
Removes all HTML tags and their content from a String (e.g. {{ '<script>Hello World</script>' | strip_tags }} #=> ""
).
# Stylesheet Tag
Generates the HTML <link>
tag for a CSS template, taking as parameters the URL and attributes (e.g. attr: 'value'
, {{ 'my-css-url' | stylesheet_tag: media: 'screen', title: 'color style' }}
=> <link href='my-css-url' rel='stylesheet' type='text/css' media='screen' title='color style' />
).
# Theme Javascript
Adds a theme tag in Javascript (e.g. {{ 'home-page-javascript' | theme_javascript }}
).
# Theme Stylesheet
Adds a theme tag in CSS (e.g. {{ 'home-page-stylesheet' | theme_stylesheet }}
).
# Time Ago in Words
Converts a date in String to words (e.g. {{ '01-02-2019' | time_ago_in_words }} #=> 'over 3 years'
).
# Translate
Resolves the translation text for Site keys. Custom values will be returned if they exist (e.g. {{ 'admin.logs.errors.no_logs_yet' | translate }}
).
# Truncate HTML
Returns a String after truncating it (e.g. {{ html | truncate_html: 10 }}
).
# Video Player
Adds a video player in HTML code using a File Manager asset (e.g. {{ movie1 | video_player: 320, 320 }}
).
Parameters
video
(Asset) — Video-type object from the File Manager.width
(Integer) — Video width.height
(Integer) — Video height.
# Step
These are the liquid filters that alter values related to steps in Modyo Platform.
# By UID
Returns the Step with the selected UID. e.g. {% assign my_step = origination.steps | by_uid: 'step-01' %}
Parameters:
- steps (ArrayStep) - array with steps
- uid (String) - Step UID
# Submission
These are the liquid filters that alter values related to submissions in Modyo Platform.
# By Origination
Returns the Submissions filtered by Origination UID. e.g. {% assign filtered_submissions = user.submissions | by_origination: 'my-origination' %}
Parameters:
- submissions (ArraySubmission) - array with user submissions
- uid (String) - Origination UID
# By Status
Returns the Submissions with the selected status. e.g. {% assign filtered_submissions = user.submissions | by_status: 'completed' %}
Parameters:
- submissions (ArraySubmission) - array with user submissions
- status (String) - Originations status. Supported values are 'pending', 'completed' and 'all'
# Task
These are the liquid filters that alter values related to tasks in Modyo Platform.
# By UID
Returns the Task with the selected UID. e.g. {% assign my_task = step.tasks | by_uid: 'task-01' %}
Parameters:
- tasks (ArrayTask) - array with tasks
- uid (String) - Task UID
# User
These Liquid filters alter values related to Users.
# Default Avatar Image
Shows the default avatar image (e.g. {{ user | avatar_for: 'C50x50' }}
).
Parameters
user
(User) — User object.size
(Integer) (default: 'C50x50') — Image size.
# Image For
Shows the HTML code for a user's image (e.g. {{ user | avatar_for: 'C50x50', true }}
).
Parameters
user
(User) — User object.size
(Integer) (default: 'C50x50') — Image size.link
(Boolean) (default: true) —true
adds a link to the user's profile.
# Widget
These Liquid filters alter values related to Widgets.
# Entry Limit
Determines the entry limit for a widget (e.g. {{ widget1 | entry_limit }}
).
# Resolve Home Widget List
Returns a list of all widgets that belong to a Site (e.g. {{ site | resolve_home_widget_list }}
).
# Resolve Me Widget List
Returns a list of all widgets that belong to a "me" page (e.g. {{ site | resolve_me_widget_list }}
).
# Resolve Widget List
Returns a list of all widgets that belong to a page (e.g. {{ site | resolve_widget_list: page }}
).
Parameters
site
(Site) — Site-type object.page
(Page) — Page-type object.