Output tag
Output tag is used to output information. It looks like this: {{ output }}
, and it displays or execute liquid statement that is found between its curly braces.
Filters
Filters manipulate what output tag generates. For example, if you want to show an amount of 289 and you want to display them in a currency format in Versaccounts.
You will write the liquid statement like this
{{ variablename | currency: invoice.currency }}
currency in this example is a filter and it manipulate the value stored in variablename and then
display a new format.
Filter types available are:
Math filters
Math filters available are:
times (input, operand)
Multiplies input by operand.
You save {{ product.compare_at_price | minus: product.price | times: 100.0 | divided_by: product.compare_at_price }}%}
divided_by (input, operand)
Divides input by operand. In the example below, operand is 2 and 100.0
output is {{ line.amount | times: 100.0 | divided_by: 2 }}%
minus (input, operand)
Subtracts input from operand.
You save {{ product.compare_at_price | minus: product.price | money }}!
plus (input, operand)
Adds input to operand.
Showing {{ paginate.current_offset }}-{{ paginate.current_offset | plus: paginate.page_size }} items.
Manipulation filters
Manipulation filters available to you are:
- append (input)
- capitalize
- date (input, format)
- downcase
- first
- join (input, segmenter = '')
- last
- newline_to_br
- prepend
- remove
- remove_first
- replace
- replace_first
- size
- sort (input, property = nil)
- split
- strip
- lstrip
- rstrip
- truncate (input, characters = x)
- truncatewords (input, words = x)
- upcase
- as_text
append (input)
Use this filter to append characters to a string.
Input
{{ 'bob' | append: ' doe' }}
Output
bob doe
capitalize
Capitalizes the first word of text
Input
{{ 'bob doe' | capitalize }}
Output
Bob doe
date (input, format)
Changes the date format.
%a |
Abbreviated weekday ("Sun"). |
%A |
Full weekday name ("Sunday"). |
%b |
The abbreviated month name ("Jan"). |
%B |
The full month name ("January"). |
%c |
The preferred local date and time representation. |
%d |
Day of the month, zero padded (01.31). |
%-d |
Day of the month, not padded (1.31). |
%e |
Day of the month, blank-padded ( 1.31). |
%H |
Hour of the day, 24-hour clock (00.23). |
%I |
Hour of the day, 12-hour clock (1:12). |
%j |
Day of the year (001.366). |
%K |
Hour of the day, 24-hour clock (1:12). |
%m |
Month of the year (01.12). |
%M |
Minute of the hour (00.59). |
%p |
Meridian indicator (AM/PM). |
%S |
Second of the minute (00.60). |
%U |
The number of the week in the current year, starting with the first Sunday as the first day of the first week. |
%W |
The number of the week in the current year, starting with the first Monday as the first day of the first week. |
%w |
Day of the week (Sunday is 0, so 0...6). |
%x |
Preferred representation for the date alone, no time. |
%X |
Preferred representation for the time alone, no date. |
%y |
Year without a century (00.99). |
%Y |
Year with a century. |
%Z |
Time zone name. |
%% |
Literal % character. |
Combinations |
%c - date and time (%a %b %e %T %Y) %D - Date (%m/%d/%y) %F - The ISO 8601 date format (%Y-%m-%d) %r - 12-hour time (%I:%M:%S %p) %R - 24-hour time (%H:%M) %T - 24-hour time (%H:%M:%S) |
{{ invoice.create_at| date: "%a, %b %d, %y" }}
downcase
Converts text into lowercase.
Input
{{ 'BOB' | downcase }}
Ouput
bob
first
Gets the first element in an array.
{{ invoice.invoice_items | first }}
join (input, segmenter = '')
Joins an array with a specified character (e.g. ',').
Input
{{ names | join: ',' }}
Output
name1, name2, name3
Gets the last element passed in an array.
{{ product.images | last }}
newline_to_br
Inserts a <br /> linebreak tag in front of every \n line break character.
{{ comment | newline_to_br }}
prepend
Prepends characters to a string.
Input
{{ 'sales' | prepend: 'get ' }}
Output
remove
Removes all occurences of the substring from the input.
{{ "hello world" | remove: 'hello }}
remove_first
Removes only the first occurence of the substring from the input.
{{ "hello world hello" | remove_first: 'hello' }}
replace
Replaces all occurences of a string with another.
{{ product.description | replace: 'super', 'mega' }}
replace_first
Replaces the first occurence of a string with another.
{{ product.description | replace_first: 'super', 'mega' }}
size
Returns the size of a string or an array.
Input
{{ 'hello' | size }}
Output
5
sort (input, property = nil)
Sort elements of the array provide optional property with which to sort an array of hashes or drops.
Example:
{% assign variants = product.variants | sort: 'price' %}
{% for variant in variants %}
<li>{{ variant.title }} - {{ variant.price | money }}</li>
{% endfor %}
split
Takes a string and divides it into substrings based on a delimiter.
{% assign words = "Uses cheat codes, calls the game boring." | split: ' ' %}
First word: {{ words.first }}
First word: {{ words[0] }}
Second word: {{ words[1] }}
Last word: {{ words.last }}
All words: {{ words | join: ', ' }}
{% for word in words %}
{{ word }}
{% endfor %}
Output
First word: Uses
First word: Uses
Second word: cheat
Last word: boring.
All words: Uses, cheat, codes,, calls, the, game, boring.
Uses
cheat
codes,
calls
the
game
boring.
strip
Strips tabs, spaces, and newlines (all whitespace) from the left and right sides of strings. Example:
{{ ' too many spaces ' | strip }}
Returns "too many spaces".
lstrip
Strips tabs, spaces, and newlines (all whitespace) from the left side of strings. Example:
{{ ' too many spaces ' | strip }}
Returns "too many spaces ".
rstrip
Strips tabs, spaces, and newlines (all whitespace) from the right side of strings. Example:
{{ ' too many spaces ' | strip }}
Returns " too many spaces".
truncate (input, characters = x)
Truncates a string down to 'x' characters.
{{ article.content | strip_html | truncate: 50 }}
truncatewords (input, words = x)
Truncates a string down to 'x' words.
{{ article.content | strip_html | truncatewords: 20 }}
upcase
Converts a string to UPPER CASE.
Input
{{ 'i want this to be uppercase' | upcase }}
Output
I WANT THIS TO BE UPPERCASE
as_text
Display text and preserve line breaks in the text
Input
{{ 'text with line breaks' | as_text }}
Currency filters
Money filters available to you are:
currency
Display a number according to the currency passed in.
{{ 33 | currency: USD_currency_object }}
Output
$33.00
Comments and Suggestions
0 comments
Please sign in to leave a comment.
Related articles