Close

BLOGS

D365 CRM Portal: Filters in Liquid Template in Dynamics 365 Portal

 

Filter Description Example
INPUT OUTPUT
abs Returns the absolute value of a number. {{ -10 | abs }} 10
{{ 5 | abs }} 5
append Concatenates two strings and returns the concatenated value. {{ "/home/aboutus/history" | append: ".html" }} /home/aboutus/history.html
{% assign filename = "/index.html" %} {{ "abc.com" | append: filename }} abc.com/index.html
at_least Limits a number to a minimum value. {{ 4 | at_least: 5 }} 5
{{ 4 | at_least: 3 }} 4
at_most Limits a number to a maximum value. {{ 4 | at_most: 5 }} 4
{{ 4 | at_most: 3 }} 3
capitalize Makes the first character of a string capitalized. capitalize only capitalizes the first character of the string, so later words are not affected. {{ "title" | capitalize }} Title
{{ "my great title" | capitalize }} My great title
ceil Rounds the input up to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied. {{ 1.2 | ceil }} 2
{{ "3.5" | ceil }} 4
compact Removes any nil values from an array. {% assign site_categories = site.pages | map: 'category' %}
{% for category in site_categories %}
{{ category }}
{% endfor %}
business
celebrities
lifestyle
sports
technology
{% assign site_categories = site.pages | map: 'category' | compact %}
{% for category in site_categories %}
{{ category }}
{% endfor %}
My great title
concat Concatenates (joins together) multiple arrays. The resulting array contains all the items from the input arrays. {% assign fruits = "apples, oranges, peaches" | split: ", " %}
{% assign vegetables = "carrots, turnips, potatoes" | split: ", " %}
{% assign everything = fruits | concat: vegetables %}
{% for item in everything %}
- {{ item }}
{% endfor %}
- apples
- oranges
- peaches
- carrots
- turnips
- potatoes
{% assign furniture = "chairs, tables, shelves" | split: ", " %}
{% assign everything = fruits | concat: vegetables | concat: furniture %}
{% for item in everything %}
- {{ item }}
{% endfor %}
- apples
- oranges
- peaches
- carrots
- turnips
- potatoes
- chairs
- tables
- shelves
date Converts a timestamp into another date format. The format for this syntax is the same as strftime. The input uses the same format as Ruby’s Time.parse. {{ article.published_at | date: "%a, %b %d, %y" }} Fri, Jul 17, 15
{{ article.published_at | date: "%Y" }} 2015
{{ "March 14, 2016" | date: "%b %d, %y" }} Mar 14, 16
This page was last updated at {{ "now" | date: "%Y-%m-%d %H:%M" }}. This page was last updated at 2018-06-07 16:22.
default Allows you to specify a fallback in case a value doesn’t exist. default will show its value if the left side is nil, false, or empty.In this example, product_price is not defined, so the default value is used. {{ product_price | default: 2.99 }} 2.99
{% assign product_price = 4.99 %}
{{ product_price | default: 2.99 }}
4.99
{% assign product_price = "" %}
{{ product_price | default: 2.99 }}
2.99
divided_by Divides a number by the specified number. The result is rounded down to the nearest integer (that is, the floor) if the divisor is an integer. {{ 16 | divided_by: 4 }} 4
{{ 5 | divided_by: 3 }}
{{ product_price | default: 2.99 }}
1
{% assign product_price = "" %}
{{ product_price | default: 2.99 }}
2.99
Controlling rounding divided_by produces a result of the same type as the divisor — that is, if you divide by an integer, the result will be an integer. If you divide by a float (a number with a decimal in it), the result will be a float. {{ 20 | divided_by: 7 }} 2
{{ 20 | divided_by: 7.0 }} 2.857142857142857
Changing variable types You might want to use a variable as a divisor, in which case you can’t simply add .0 to convert it to a float. In these cases, you can assign a version of your variable converted to a float using the times filter. {% assign my_integer = 7 %}
{{ 20 | divided_by: my_integer }}
2
{% assign my_integer = 7 %}
{% assign my_float = my_integer | times: 1.0 %}
{{ 20 | divided_by: my_float }}
2.857142857142857
downcase Makes each character in a string lowercase. It has no effect on strings which are already all lowercase. {{ "Parker Moore" | downcase }} parker moore
{{ "apple" | downcase }} apple
escape Escapes a string by replacing characters with escape sequences (so that the string can be used in a URL, for example). It doesn’t change strings that don’t have anything to escape. {{ "Have you read 'James & the Giant Peach'?" | escape }} Have you read 'James & the Giant Peach'?
{{ "Tetsuro Takara" | escape }} Tetsuro Takara
escape_once Escapes a string without changing existing escaped entities. It doesn’t change strings that don’t have anything to escape. {{ "1 < 2 & 3" | escape_once }} 1 < 2 & 3
{{ "1 < 2 & 3" | escape_once }} 1 < 2 & 3
first Returns the first item of an array. {% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array.first }}
apples
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
{{ my_array.first }}
zebra
floor Rounds a number down to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied. {{ 1.2 | floor }} 1
{{ 2.0 | floor }} 2
{{ 183.357 | floor }} 183
{{ "3.5" | floor }} 3
join Combines the items in an array into a single string using the argument as a separator. {% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
{{ beatles | join: " and " }}
John and Paul and George and Ringo
last Returns the last item of an array. {% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array.last }}
plums
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
{{ my_array.last }}
tiger
lstrip Removes all whitespaces (tabs, spaces, and newlines) from the beginning of a string. The filter does not affect spaces between words. {{ " So much room for activities! " | lstrip }} So much room for activities!
map Creates an array of values by extracting the values of a named property from another object.
In this example, assume the object site.pages contains all the metadata for a website. Using assign with the map filter creates a variable that contains only the values of the category properties of everything in the site.pages object.
{% assign all_categories = site.pages | map: "category" %}
{% for item in all_categories %}
{{ item }}
{% endfor %}
business
celebrities
lifestyle
sports
technology
minus Subtracts a number from another number. {{ 4 | minus: 2 }} 2
{{ 16 | minus: 4 }} 12
{{ 183.357 | minus: 12 }} 171.357
modulo Returns the remainder of a division operation. {{ 3 | modulo: 2 }} 1
{{ 24 | modulo: 7 }} 3
{{ 183.357 | modulo: 12 }} 3.357
newline_to_br Replaces every newline (\n) with an HTML line break (
).
{% capture string_with_newlines %} Hello
there
{% endcapture %}
{{ string_with_newlines | newline_to_br }}
<br />
Hello
there
plus Adds a number to another number. {{ 4 | plus: 2 }} 6
{{ 16 | plus: 4 }} 20
{{ 183.357 | plus: 12 }} 195.357
prepend Adds the specified string to the beginning of another string. {{ "apples, oranges, and bananas" | prepend: "Some fruit: " }} Some fruit: apples, oranges, and bananas
{% assign url = "liquidmarkup.com" %}
{{ "/index.html" | prepend: url }}
liquidmarkup.com/index.html
remove Removes every occurrence of the specified substring from a string. {{ "I strained to see the train through the rain" | remove: "rain" }} I sted to see the t through the
remove_first Removes only the first occurrence of the specified substring from a string. {{ "I strained to see the train through the rain" | remove_first: "rain" }} I sted to see the train through the rain
replace Replaces every occurrence of an argument in a string with the second argument. {{ "Take my protein pills and put my helmet on" | replace: "my", "your" }} Take your protein pills and put your helmet on
replace_first Replaces only the first occurrence of the first argument in a string with the second argument. {% assign my_string = "Take my protein pills and put my helmet on" %}
{{ my_string | replace_first: "my", "your" }}
Take your protein pills and put my helmet on
reverse Reverses the order of the items in an array. reverse cannot reverse a string. {% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array | reverse | join: ", " }}
plums, peaches, oranges, apples
{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }} .moT rojaM ot lortnoc dnuorG
round Rounds an input number to the nearest integer or, if a number is specified as an argument, to that number of decimal places. {{ 1.2 | round }} 1
{{ 2.7 | round }} 3
{{ 183.357 | round: 2 }} 183.36
rstrip Removes all whitespace (tabs, spaces, and newlines) from the right side of a string. {{ " So much room for activities! " | rstrip }} So much room for activities!
size Returns the number of characters in a string or the number of items in an array. size can also be used with dot notation (for example, {{ my_string.size }}). This allows you to use size inside tags such as conditionals. {{ "Ground control to Major Tom." | size }} 28
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} {{ my_array | size }} 4
slice Returns a substring of 1 character beginning at the index specified by the argument passed in. An optional second argument specifies the length of the substring to be returned. String indices are numbered starting from 0. {{ "Liquid" | slice: 0 }} L
{{ "Liquid" | slice: 2 }} q
{{ "Liquid" | slice: 2, 5 }} quid
{{ "Liquid" | slice: -3, 2 }} ui
sort Sorts items in an array by a property of an item in the array. The order of the sorted array is case-sensitive. {% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
{{ my_array | sort | join: ", " }}
Sally Snake, giraffe, octopus, zebra
sort_natural Sorts items in an array by a property of an item in the array. {% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
{{ my_array | sort_natural | join: ", " }}
giraffe, octopus, Sally Snake, zebra
split Divides an input string into an array using the argument as a separator. split is commonly used to convert comma-separated items from a string to an array. {% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
{% for member in beatles %}
{{ member }}
{% endfor %}
John
Paul
George
Ringo
strip Removes all whitespace (tabs, spaces, and newlines) from both the left and right side of a string. It does not affect spaces between words. {{ " So much room for activities! " | strip }} So much room for activities!
strip_html Removes any HTML tags from a string. {{ "Have you read Ulysses?" | strip_html }} Have you read Ulysses?
strip_newlines Removes any newline characters (line breaks) from a string. {% capture string_with_newlines %}
Hello
there
{% endcapture %}
{{ string_with_newlines | strip_newlines }}
Hellothere
times Multiplies a number by another number. {{ 3 | times: 2 }}/td> 6
{{ 24 | times: 7 }} 168
{{ 183.357 | times: 12 }} 2200.284
truncate truncate shortens a string down to the number of characters passed as a parameter. If the number of characters specified is less than the length of the string, an ellipsis (…) is appended to the string and is included in the character count. {{ "Ground control to Major Tom." | truncate: 20 }} Ground control to...
Custom ellipsis truncate takes an optional second parameter that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (…), but you can specify a different sequence.
The length of the second parameter counts against the number of characters specified by the first parameter. For example, if you want to truncate a string to exactly 10 characters, and use a 3-character ellipsis, use 13 for the first parameter of truncate, since the ellipsis counts as 3 characters.
{{ "Ground control to Major Tom." | truncate: 25, ", and so on" }} Ground control, and so on
No ellipsis You can truncate to the exact number of characters specified by the first parameter and show no trailing characters by passing a blank string as the second parameter: {{ "Ground control to Major Tom." | truncate: 20, "" }} Ground control to Ma
truncatewords Shortens a string down to the number of words passed as the argument. If the specified number of words is less than the number of words in the string, an ellipsis (…) is appended to the string. {{ "Ground control to Major Tom." | truncatewords: 3 }} Ground control to...
Custom ellipsis truncatewords takes an optional second parameter that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (…), but you can specify a different sequence. {{ "Ground control to Major Tom." | truncatewords: 3, "--" }} Ground control to--
No ellipsis You can truncate to the exact number of characters specified by the first parameter and show no trailing characters by passing a blank string as the second parameter: {{ "Ground control to Major Tom." | truncatewords: 3, "" }} Ground control to
uniq Removes any duplicate elements in an array. {% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %}
{{ my_array | uniq | join: ", " }}
ants, bugs, bees
upcase Makes each character in a string uppercase. It has no effect on strings which are already all uppercase. {{ "Parker Moore" | upcase }} PARKER MOORE
{{ "APPLE" | upcase }} APPLE
url_decode Decodes a string that has been encoded as a URL or by url_encode. {{ "%27Stop%21%27+said+Fred" | url_decode }} 'Stop!' said Fred
url_encode Converts any URL-unsafe characters in a string into percent-encoded characters. {{ "john@liquid.com" | url_encode }} john%40liquid.com
{{ "Tetsuro Takara" | url_encode }} Tetsuro+Takara

Print
Posted: Sep 9, 2018,
Categories: Microsoft Portals,
Comments: 0,
Author: Urish Arora
Rate this article:
5.0

Urish AroraUrish Arora

Other posts by Urish Arora

, Contact author

Please login or register to post comments.

Name:
Email:
Subject:
Message:
x

SEARCH

Categories

Subscribe to our blog

«November 2019»
MonTueWedThuFriSatSun
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

  • Featured Posts
  • Recent Posts
  • Recent Comments
Dynamics365Authority is a community platform for Professionals and Students to contribute or share their knowledge and skills on Microsoft Dynamics 365 Technologies. Our primary goal is to invite professionals on Dynamics 365 technology across the world to contribute & share their knowledge and skills through their blogs so that we can help other developers.
Stay updated with Dynamics 365 technology. Improve skills and knowledge from our blogs, articles and code snippets. Learn it. Follow professionals and learn from them.
Unified Service Desk Book(Online Edition) 

FOLLOW US

Stay connected with us on our social media channels for latest articles, blogs posts etc.  We will keep updating regularly on our social media platform and web platform.

FACEBOOK

Follow us on Facebook

 

TWITTER

View all our tweets

 

DYNAMICS365AUTH

Join us now

 

BLOGS

View our blogs

 

 

Latest Blog

Posted: Jun 20, 2019

Overview - Appendix (Unified Service Desk)

This blog is about Appendix

Read more
Posted: Jun 20, 2019

Overview - Troubleshoot and Debug (Unified Service Desk)

This blog is about Troubleshoot and Debug in Unified Service Desk

Read more
Posted: Jun 20, 2019

Overview - Performance (Unified Service Desk)

This blog is about the Performance in Unified Service Desk

Read more
RSS

ADDITIONAL RESOURCES

Dynamics 365 Authority.com - Search the library for "Dynamics 365"

  What's New in Dynamics 365

  Dynamics 365 Documentation

  

  Sign-up for 30 days trial

 

 

Recent comments

Ashish:

Nice blog. Very helpful to get all references to white papers at one place.

Previous Next

About Us

Here comes the Dynamics 365 Authority - Great technical blog posts are hidden gems. They are hard to find simply because not enough of us write them in the first place. Yet technical blogging is one of the best things we can do not only for ourselves, but also as members of the wider community of developers.

Dynamics 365 Authority leverages this platform to help developers and users to move from traditional paper-based process to modern digital business process. Dynamics365Authority.com helps your business grow, evolve and transform.

Dynamics365Authority.com is your Digital Transformation Partner

Recent Posts

Overview - Appendix (Unified Service Desk)

This blog is about Appendix
  • 238
  • Article rating: 5.0

Overview - Troubleshoot and Debug (Unified Service Desk)

This blog is about Troubleshoot and Debug in Unified Service Desk
  • 359
  • Article rating: 5.0
RSS

Get in touch

Follow Us

 

Tag cloud: Dynamics365Authority.com with Urish Arora; Dynamics365Authority.com; Sales; Leading community site on MS Dynamics 365; Dynamics 365 Authority; Service;Top CRM Blogs; Urish Arora - Australia's leading expert on Digital Transformation;  Digital Transformation; Field Service;Top Articles on MS Dynamics CRM Relationship Insights; Office 365 Security Compliance; Project Service; Microsoft Dynamics 365 for Sales; Relevance Search; Goal Metrics; Activities and Case; Sales Literature;Knowledge Management;

Terms Of UsePrivacy StatementCopyright 2019 by Dynamics365Authority
Back To Top