The liquid is a template language developed by Shopify. It is available as an open-source project on GitHub and is used by many different software projects and companies. We can also modify our output by creating a marked logic or changing it directly with a filter. Items and properties of an object are extracted using one of six basic data types. Liquid also integrates sensible and comparable basic operators for use with tags.
Template language allows you to create a single template to handle static content, and enter information by force depending on where the template is provided. For example, you can create a product template that handles all of your typical product specifications, such as a product image, title, and price. That template can provide those attributes with relevant content, depending on the current product being viewed.
HANDLES
The handle is used to access the signs of a liquid. By default, it is the subject of a small capital letter with any spaces and special characters replaced by hyphens (-). Everything in Liquid (product, collection, blog, menu) has a handle.
A product labelled ‘shirt’ will automatically be provided with a catch shirt. If you already have a product with a ‘shirt’ handle, the handle will automatically adjust. In other words, all the 'shirt' products created after the first one will get a handle on shirt 1, shirt 2, and so on.
1. Basic Commands
COMMAND | DESCRIPTION | SYNTAX |
---|---|---|
== | Equals (comparison) |
|
!= | Not equals |
|
> | Greater than |
|
< | Lesser than |
|
>= | Greater than and equal to |
|
<= | Lesser than and equal to |
|
or | Condition A or Condition B |
|
and | Condition A and Condition B |
|
contains | Checks for the presence of a substring |
|
2. Data Types
COMMAND | SYNTAX |
---|---|
Strings | {% assign str = 'Hello!' %} |
Numbers | {% assign intg=35%} |
Boolean | {% assign var=true %} or {% assign var=false%} |
Array |
|
3. Tag Commands
Variable Tags are used to create new Liquid variables.
COMMAND | DESCRIPTION | SYNTAX |
---|---|---|
Assign | Creates a new Variable | {% assign var = 5 %} |
Capture | Selects the string inside of the opening and closing tags and assigns it to a variable. |
|
Increment | Increments the variable every time it is called. | {% increment var %} |
Decrement | Decrements the variable every time it | {% decrement var %} |
If | Executes an if block statement. |
|
Else If | Executes an Else if the block. |
|
Case | Creates a switch clause to compare a variable with different values. |
|
Unless | Similar to if, but executes block only when conditions are not met. |
|
For | Executes a block of code continuously. |
|
For Else | Else block if For condition fails. |
|
Break | Stops the loop from iterating in the middle. |
|
Continue | This causes the loop to skip the current iteration and proceed with the loop. |
|
Cycle | Loops through a group of strings. Each time cycle is called, and the next string that was passed as a parameter is returned as the output. | {% cycle 'one', 'two', 'three' %} |
Table Row | Generates an HTML table. |
|
Comments | Part of a code which is never rendered. |
|
Liquid | Allows us to write multiple tags under a delimiter. |
|
Echo | Outputs an expression when rendered in HTML in a liquid tag |
|
Raw | Allows output of Liquid code on a page without being parsed. |
|
Section | Inserts a section from the sections folder of a theme. | {% section 'header' %} |
Style | Renders an HTML style tag in Liquid |
|
Whitespace control | Using hyphens, the assigned statement doesn't output a blank line. | {%- assign my_variable = "tomato" -%} |
4. Theme Tags
TAGS | DESCRIPTION |
---|---|
{% include %} | Inserts a snippet from the snippets folder of a theme. |
{% form %} | Creates a form element in HTML with necessary attributes. |
{% paginate %} | Works in conjunction with for tags to split the content into numerous pages. |
{%render%} | Renders a snippet from the snippets folder of a theme. |
5. Filters
COMMAND | DESCRIPTION | SYNTAX |
---|---|---|
Font Face | Returns a CSS font face declaration to load the chosen font. |
|
Font Modify | It takes two arguments. The first indicates which property must be changed and the second one indicates what modification must be made. |
|
Font Url | Returns a CDN URL for the chosen font. It returns woff2 by default. | { settings.type_header_font | font_url }} |
Date | Converts an existing date to another format. | {{ article.published_at| date: "%a, %b %d, %y" }} |
Default | Sets a default value no value is assigned to a variable. | Dear {{ student.name | default: "student" }} |
Default Errors | Outputs default error messages for the form.errors variable. |
|
Default Pagination | A set of links for paginated results are created. | {{ paginate | default_pagination }} |
Format Address | Prints the elements in an address according to their locale. | {{ address | format_address }} |
Highlight | Words are wrapped inside search results with HTML <strong> tag with highlight class. | {{ item.content | highlight: search.terms }} |
Highlight Active | A tag link is wrapped in a span with the class active. |
|
JSON | Converts a string to the JSON format. | var content = {{ pages.page-handle.content | json }}; |
Placeholder_SVG_Tag | Takes a placeholder name and outputs a placeholder SVG illustration. | {{ 'clctn1' | placeholder_svg_tag }} |
T(translation) | It uses a translation key to access the locale file for the active language and returns the corresponding string of translated text in the locale file. | { 'products.product.sold_out' | t }} |
Weight with unit. | Formats the weight. | {{ product.variants.first.weight | weight_with_unit }} |
String Concatenation | Merges an array with another array. | {% assign str3 = str1 | concat: str2 %} |
Join | Joins the elements in an array based on a character passed as a parameter. | {{ product.tags | join: ', ' }} |
First | Returns the first element in an array. | {{ product.tags | first }} |
Index | Returns the item stored at a specific index. | {{ product.tags[10] }} |
Last | Returns the last element of the array. | {{ product.tags | last }} |
Map | Accepts an array element value as a parameter and makes a string out of each array element’s value. | {{ collections | map: 'name' }} |
Reverse | Reverses the array. | {{ arr| reverse | join: ", " }} |
Size | Returns the length of an array. | {{ arr | size }} |
Sort | Sorts the array. | {% assign arr = collection.products | sort: 'title' %} |
Uniq | Removes duplicate elements. | {{ array | split: ' ' | uniq | join: ' ' }} |
Where | Creates an array will all values based on a certain condition. | {% assign array = collection.products | where: "type", "ABC" %} |
Metafield Tag | Generates an HTML element depending on the meta field. | {{ product.metafields.instructions.wash | metafield_tag }} |
Metafield Text | Generates a text version of Metafield. | {{ product.metafields.instructions.wash | metafield_text }} |
Currency Selector | Displays a drop-down menu for customers to choose a particular currency. |
|
Img_tag | Creates an image tag. | {{ 'penguin_gnome.gif' | asset_url | img_tag }} |
Payment Button | Creates a checkout button. | {{ form | payment_button }} |
Payment Terms | Renders the Shop Pay Installments banner for a product. | {{ form | payment_terms }} |
Payment Type SVG | Returns SVG tag for a requested payment type image. |
|
Script Tag | Generates a script tag. | {{ 'store.js' | asset_url | script_tag }} |
Stylesheet Tag | Generates a link that refers to a given stylesheet. | {{ 'store.css' | asset_url | stylesheet_tag }} |
Time Tag | Converts a time to an HTML time tag. | {{ form.published_at | time_tag }} |
Money | Format the value based on the ‘HTML without currency’ setting. | {{ 200 | money }} |
Money with currency. | Format the value based on the ‘HTML without currency’ setting. | {{ 2.95 | money_with_currency }} |
Money with trailing zeros | Excludes the decimal point and trailing zeroes. | {{ 90.00 | money_without_trailing_zeros }} |
Money without currency | Formats the price based on decimals. | {{ 2.59 | money_without_currency }} |
Abs | Returns the absolute value. | {{ -99 | abs }} |
At least | Limits a number to the least value. | {{ 4 | at_least: 10 }} |
At most | Limits a number to a higher value. | {{ 4 | at_most: 10 }} |
Ceil | Rounds the number up to the nearest int value. | {{ 4.2 | ceil }} |
Divided by | Divides the output by a number | {{ 200 | divided_by: 10 }} |
Floor | Rounds the output down to the nearest int value. | {{ 4.2 | floor }} |
Minus | Subtracts a value. | {{ 200 | minus: 10 }} |
Round | Rounds the output to the nearest integer to a specified number of decimals. | {{ 3.14159 | round: 2 }} |
Times | Multiplies by a number. | {{ 200 | times: 10 }} |
Modulo | Returns Remainder after division. | {{ 200 | modulo:10 }} |
Append | Appends chars to a string. | {{ 'store' | append: '.txt' }} |
Camel Case | Converts a hyphenated string to camel case. | {{ 'shopify-liquid' | camelcase }} |
Capitalize | Capitalizes the first letter of each word. | {{ 'upper case' | capitalize}} |
Downcase | Converts a string to lowercase. | {{ 'LOWERCASE' | downcase }} |
Escape | Escapes a string. | {{ "<p>text</p>" | escape }} |
Handleize | Formats a string into a handle. | {{ '100% M & Ms!!!' | handleize }} |
New Line to br | Inserts a page break. | {{ array | newline_to_br }} |
Pluralize | Returns a singular or plural version of the string based on the number. | {{ cart.item | pluralize: 'item', 'items' }} |
Prepend | Prepends a character to an existing string. | {{ ‘day’ | prepend: ‘Have a great ' }} |
Remove | Removes an occurrence in a substring. | {{ "Hello, world. Bye,Bye." | remove: "world" }} |
Replace | Replaces all the occurrences of a particular string. | {{ product.title | replace: 'Clothes', 'products' }} |
Slice | Returns substring specified at an index. | {{ "shopify" | slice: 1, 4 }} |
Split | A substring is used as a delimiter. | {% assign words = "Hi, how are you?" | split: ' ' %} |
Strip | Strips tabs, spaces, and newlines from left and right. | {{ ' too many spaces ' | strip }} |
Lstrip | Strips tabs, spaces, and newlines from left. | "{{ ' too many spaces ' | lstrip }} |
Rstrip | Strips tabs, spaces, and newlines from right. | {{ ' too many spaces ' | rstrip }} |
Strip HTML | Strips all HTML Tags. | {{ "<h1>Shopify</h1> Liquid" | strip_html }} |
Upcase | Converts string to uppercase. | {{ ‘uppercase’| upcase }} |
Brightness Difference | Calculates the perceived brightness of two colors. | {{ '#fff00f' | brightness_difference: '#0b72ab' }} |
Color Brightness | Returns the perceived brightness of a given color. | {{ '#7ab55c' | color_brightness }} |
Color Contrast | Calculates ratio between two colors. | {{ '#495859' | color_contrast: '#fffffb' }} |
Color Darken | Increases the darkness of the input color. | {{ '#7ab55c' | color_darken: 10 }} |
Color Desaturate | Desaturates the input color. | {{ '#7ab55c' | color_desaturate: 10 }} |
Color Extract | Extracts a component from the given color. | {{ '#7ab55c' | color_extract: ‘blue’ }} |
Color Lighten | Lightens the input color. | {{ '#7ab55c' | color_lighten: 10 }} |
Color Mix | Blends two colors. | {{ '#7ab55c' | color_mix: '#ffc0cb', 50 }} |
Color RGB | Converts a CSS string to CSS rgb(). | {{ '#7ab55c' | color_to_rgb }} |
External Video Tag | An Iframe is generated that contains a youtube player. |
|
Image Tag | Generates an image tag for the media’s preview picture. |
|
Media Tag | Generates a tag for media. |
|
Model Viewer Tag | Generates a google model viewer in 3D. |
|
Asset Image URL | Returns asset URL of an Image. | {{ ‘shopify.png' | asset_img_url: '100x' }} |
File Image URL | Returns the Image URL. | {{ 'shopify.png' | file_img_url: '100x' }} |
File URL | Returns URL of a file. | {{ 'shopify.pdf' | file_url }} |
Customer Link Login | Generates a link to the login page for customers. | {{ 'Log in' | customer_login_link }} |
Global Asset URL | Returns Global Asset URL. | {{‘shopify.js' | global_asset_url | script_tag }} |
Link To | Generates a HTML hyperlink. | {{ 'shopify' | link_to: 'https://www.shopify.com', ' link to Shopify' }} |
Link to Tag | Generates a link for all products in a collection. |
|
Payment Type Image | Returns URL of payment SVG Image. |
|
Shopify Assets URL | Returns the URL of a global asset that is found on Shopify’s servers. | {{ 'shopify.js' | shopify_asset_url | script_tag }} |
6. Objects
1. GENERIC COMMANDS
COMMAND | DESCRIPTION | SYNTAX |
---|---|---|
All Products | Returns a list of all products. | {{ all_products[‘shopify store’].title }} |
Articles | Returns a list of all the blog articles in a store. | {% assign article = articles['news/shopify'] %} |
Current Page | Returns the page number you are in, in paginated content. | { {page_title }} - Page: {{ current_page }} |
Page Description | Returns description of a page, collection or product. | {{ page_description }} |
Page Title | Returns the title of a page, collection or product. | {{ page_title }} |
Pages | Returns a list of all the pages in your store. | <h1>{{ pages.about.title }}</h1> |
Settings | Returns a list of the settings in your published theme.the |
|
Collection All products | Returns the number of products in a given collection. | {{ collection.all_products_count }} |
Collection All Tags | Returns a list of Tags in the collection. | {{collection.all_tag}} |
Collection All types | Returns a list of all product types. |
|
Collection Description | Returns description of a collection. | {{collection.description}} |
Collection Handle. | Returns the handle of the collection. | {{collection.handle}} |
Collection ID | Returns the unique ID of the collection. | {{collection.id}} |
Collection Image | Returns the collection Image. |
|
Collection Title | Returns Collection Title. | <h2>{{ collection.title }}</h2> |
Collection URL | Returns URL of collection. | {{collection.url}} |
Content for header | Dynamically loads all scripts required for Shopify into doc head. | {{ content_for_header }} |
Content for Index | Contains dynamic sections to be rendered on the home page. | {{ content_for_index }} |
Content for Layout | Similar to content for the index but for collection.liquid or cart.liquid. | {{ content_for_layout }} |
2. BLOCKS
Contents and settings are represented by a single block in an array of section blocks.
Syntax | Description |
---|---|
block.id | Returns a unique and dynamically allocated ID generated by Shopify. |
block.settings | Retrieve the settings of a block using its block id. |
Block.type | Returns the type defined in the block’s schema. |
3. CUSTOMER OBJECTS
Contains information about customer accounts.
Syntax | Description |
---|---|
customer_address.first_name | Returns the first name of the customer. |
customer_address.last-name | Returns the last name of the customer. |
customer_address.address1 | Returns the value of the address1 field. |
customer_address.address2 | Returns the value of the address2 field. |
customer_address.street | Returns the value of the street field. |
customer_address.company | Returns the value of the company field. |
customer_address.city | Returns the value of the city field. |
customer_address.province | Returns the value of the province field. |
customer_address.zip | Returns the value of the zip code field. |
customer_address.country_code | Returns the value of the country code field. |
customer_address.phone | Returns the value of the phone number field. |
customer_address.id | Returns the id of the customer address. |
4. DISCOUNT ALLOCATION
Contains information about all the discounts available and applicable.
Syntax | Description |
---|---|
discount_allocation.amount | The discount amount is to be deducted. |
discount_allocation.discount_application | The discount application allocates the amount on the line item. |
5. FILTER VALUE
Represents an individual value from a filter object.
Syntax | Description |
---|---|
filter_value.active | Returns a Boolean value. Checks if the filter value is active. |
filter_value.count | Returns how many results are related to the filter value. |
filter_value.url_to_add | Returns the current page URL. |
6. LINE ITEMS
Represents a single line of items in a shopping cart.
Syntax | Description |
---|---|
line_item.final_line_price | Returns the price of the line item including all line-level discount amounts. |
line_item.fulfillment | Returns fulfilment of line items. |
line_item.grams | Returns the weight in grams. |
line_item.image | Returns the line item image. |
line_item.id | Returns the id of the line item. |
line_item.key | Returns a unique identifier for each item in the cart. |
line_item.message. | Returns the discount message. |
line_item.original_line_price | Returns the original price of the line. |
line_item.product | Returns the products in the line. |
line_item.product_id | Returns the product ids of items in the line. |
line_item.quantity | Returns the number of products in each line. |
line_item.title | Returns the title of the line. |
line_item.url | Returns the URL to the product page. |
line_item.vendor | Returns the name of the vendor. |
7. FULFILLMENT
Syntax | Description |
---|---|
fulfillment.tracking_company | Returns the name of fulfilment services. |
fulfillment.tracking_number | Returns a fulfilment’s tracking number |
fulfillment.tracking_url | Returns the URL for the tracking number. |
fulfillment.item_count | Returns the total number of items in the fulfilment. |
8. LOCATION
The location object contains location information for stores.
Syntax | Description |
---|---|
location.id | Returns the location ID |
location.latitude | Returns the latitude of the location. |
location.longitude | Returns the longitude of the location. |
Location.name | Returns the name of the location. |
9. LINKLIST
Used to make a menu on the navigation page.
Syntax | Description |
---|---|
linklist.handle | Returns the handle of the link list. |
Linklist.level | Returns the number of nested levels. |
Linklist.links | Returns the array of links. |
linklist.title | Returns the title of the link list. |
10. COUNTRY
Syntax | Description |
---|---|
Country.currency | Returns the currency used in the country. |
country.iso_code | Returns the iso code of a country. |
Country.name | Returns the name of a country. |
11. VIDEO
Syntax | Description |
---|---|
video.alt | Returns the alt tag of a video. |
video.duration | Returns the duration of a video. |
Video.id | Returns the id of a video. |
video.position | Returns position of video in the product. |
Video.source | Returns the source of the video. |
12. TRANSACTION
Syntax | Description |
---|---|
transaction.id | Returns the transaction ID. |
transaction.amount | Returns the transaction amount. |
transaction.name | Returns the name of the transaction. |
transaction.status | Returns the status of the current transaction. |
transaction.created_at | Returns the timestamp when the transaction was initiated. |
transaction.receipt | Returns the payment receipt of the transaction. |
13. VARIANT
Syntax | Description |
---|---|
variant.available | Returns a Boolean value based on the availability of a variant. |
variant.barcode | Returns the barcode of a variant. |
variant.compare_at_price | Returns the variant compare at price. |
variant.matched | Returns whether the variant has been matched. |
variant.id | Returns the id of the variant. |
variant.image | Returns the image of the variant. |
variant.incoming | Returns true if a batch of inventory is incoming |
variant.unit_weight | Returns unit of weight. |
variant.url | Returns the variant's absolute URL. |
variant.unit_price | Returns the unit price of a variant. |
variant.title | Returns the concatenation of all the variant’s option values. |
variant.taxable | Returns whether a variant is taxable or not. |
variant.selected | Returns true if the variant is selected. |
14. THEME
Syntax | Description |
---|---|
theme.id | Returns the theme id. |
theme.role (deprecated) | Return(s) the role of a theme. |
theme.name | Returns the name of the theme. |
15. TAXLINE
Syntax | Description |
---|---|
tax_line.title | Returns the title of the tax |
tax_line.price | Returns the amount of tax. |
tax_line.rate | Returns the rate of tax. |
tax_line.rate_percentage | Returns rate of tax in a percentage format. |
16. REQUEST
Syntax | Description |
---|---|
request.design_mode | Returns true if a request is being made from the theme editor. |
request.host | Returns which domain the customer is accessing from. |
request.locale | Returns shop locale of the current request. |
request.path | Returns a path to the page. |
17. SHIPPING METHOD
Syntax | Description |
---|---|
shipping_method.handle | Returns handle of shipping method. |
Shipping_method.original_price | Returns original price of shipping method. |
shipping_method.price | Returns the price of the shipping method. |
shipping_method.title. | Returns title of shipping method. |
18. CART
Syntax | Description |
---|---|
cart.attributes | Captures information about the cart page. |
cart.currency | Returns the currency of the cart. |
cart.item_count | Return the number of items in the cart. |
Cart.note | Allows capturing more information on the cart page. |
cart.original_price | Returns the original price of products in the cart. |
cart.total_discount | Returns the total discount |
cart.total_price | Returns the total price of products in the cart. |
cart.total_weight | Returns the total weight of the cart. |
19. PRODUCT
Syntax | Description |
---|---|
product.available | Returns true if the product is available for purchase |
product.collections | Returns an array of collections of all products. |
product.compare_at_price_max | Returns the highest compared to price. |
product.compare_at_price_min | Returns the least compared to price. |
Product.tags | Returns an array of all product tags. |
Product.template_suffix | Returns the name of the custom product template assigned. |
product.title | Returns the title of the product |
product.type | Returns the type of product. |
product.url | Returns URL of the product. |
product.vendor | Returns the vendor of the product. |
product.url | Returns the product ID |
product.content | Returns the description of the product. |
product.price | Returns the price of the product |
product.price_max | Returns the maximum price of the product |
product.price_min | Returns the minimum price of the product. |
20. ROUTES
Used to create Dynamic URLs for the storefront.
Syntax | Description |
---|---|
routes.account_url | Returns the account URL |
routes.account_login_url | Returns the login URL |
routes.account_logout_url | Return the logout URL |
routes.account_recover_url | Returns the account recovery URL |
routes.cart_url | Returns the cart URL |
routes.cart_clear_url | Returns a URL that clears the cart. |
routes.root_url | Returns the root URL |
routes.search_url | Returns the search URL. |
21. CHECKOUT
The checkout object can be accessed on the orders page.
Syntax | Description |
---|---|
checkout.attributes | Returns the attributes of checkout |
checkout.billing_address | Returns the billing address. |
checkout.customer | Returns customer’s name |
checkout.customer | Returns the discount applied for checkout |
checkout.email | Returns email ID used during checkout |
checkout.id | Returns checkout ID. |
checkout.order_name | Returns the name of the order |
checkout.requires_shipping | Returns whether the checkout as a whole needs shipping. |
checkout.shipping_address | Returns the shipping address. |
checkout.order_number | Return the order number. |
checkout.shipping_method | Returns the method of shipping. |
checkout.shipping_price | Returns the checkout price. |
checkout.tax_lines | Returns tax lines of checkout. |
checkout.tax_price | Returns the total cost of tax per checkout. |
checkout.total | Returns the total price of checkout. |
22. ORDER
Syntax | Description |
---|---|
order.attributes | Returns custom cart attributes for the order. |
order.billing_address | Returns the order billing address. |
order.cancelled | Checks whether the order is canceled or not. |
order.cancelled_at | Returns the timestamp when the order was canceled. |
order.cancelled_reason | Returns the reason for order cancellation. |
order.cancel_reason_label | Returns the translated output of an order’s order.cancel_reason |
order.created_at | Returns the timestamp of when the order was created. |
order.customer | Returns customers associated with the order. |
order.customer_url | Returns the url of the customer's account page. |
order.discount_applications | Returns an array of discount applications. |
order.email | Returns email id associated with the order. |
order.email | Returns the financial status of the order. |
order.location | Returns the destination location of the order. |
order.name | Returns the name of the order. |
order.note | Returns the note linked with the order |
order.order_number | Return the order number. |
order.shipping_address | Returns the shipping address of the order. |
order.shipping_price | Returns the selling price of the order |
order.tax_lines | Returns the tax variable. |
order.tax_price | Returns the order’s total tax. |
order.total_discounts | Returns the total discount on the order. |
order.total_price | Returns the total price of the order. |
order.transactions | Returns array of transactions. |
23. ARTICLE
SYNTAX | DESCRIPTION |
---|---|
article.author | Returns the full name of the author of the article. |
article.comments | Returns the published comments of the article. |
article.comments_count | Returns the number of published comments. |
article.comment_post_url | Returns the URL of the post. |
article.content | Returns the content of an article. |
article.created_at | Returns the timestamp article was created. |
article.excerpt | Returns to the excerpt of the article. |
article.id | Returns the ID of the article |
article.image | Returns the image of the article. |
article.url | Returns the relative URL of the article. |
article.user | Returns an object with author information. |
article.user.bio | Returns bio of the author. |
article.user.email | Returns the email of the author. |
article.user.first_name | Returns the first name of the author. |
article.user.homepage | Return to the homepage. |
article.user.last_name | Returns the Last name of the author. |
CONCLUSION
Like any template language, Liquid acts as a bridge between an HTML file and a data store; in our case, the data is a Shopify store. This is accomplished by giving us easy-to-use and readable access to variables from within a template or Liquid file with user-friendly syntax.
By going through this cheat sheet, you would have gotten a decent understanding of Liquid by Shopify and how to implement it.
Shopify MCQ Questions
Which of the following is not a datatype in liquid?
Which of the following syntax returns the URL of payment SVG?
Which of the following is not found in an order tag?
Which of the following is true about Line Items?
Which of the following is not included in the product tag?
Which of the following is true about liquid?
Which of the following is not found in the colour tag?
Which of the following is a tax line command
a. tax_line.title
b. tax_line.price
c. tax_line.rate
d. tax_line.rate_percentage
e. tax_line.rate_cost
______ returns the cost of a product.
0 Comments