### for loop with offset parameter
Source: https://shopify.github.io/liquid/tags/iteration
Begins the loop at a specified index, skipping the initial items. The `offset` parameter determines the starting point.
```liquid
{% for item in array offset:2 %}
{{ item }}
{% endfor %}
```
--------------------------------
### for loop with continue offset
Source: https://shopify.github.io/liquid/tags/iteration
Starts a loop from where the last loop using the same iterator left off by using the `continue` keyword with the `offset` parameter.
```liquid
{% for item in array limit: 3 %}
{{ item }}
{% endfor %}
{% for item in array limit: 3 offset: continue %}
{{ item }}
{% endfor %}
```
--------------------------------
### Iterating Through Array Items
Source: https://shopify.github.io/liquid/basics/types
Use a `for` loop with the `in` keyword to iterate over all items in an array. This example assumes `site.users` is an array of names.
```liquid
{% for user in site.users %}
{{ user }}
{% endfor %}
```
--------------------------------
### Complex Order of Operations Example
Source: https://shopify.github.io/liquid/basics/operators
Illustrates a more complex evaluation of 'and' and 'or' operators, emphasizing the right-to-left processing order in Liquid.
```liquid
{% if true and false and false or true %}
This evaluates to false, since the tags are checked like this:
true and (false and (false or true))
true and (false and true)
true and false
false
{% endif %}
```
--------------------------------
### forloop object example
Source: https://shopify.github.io/liquid/tags/iteration
Demonstrates using the `forloop` object within a loop to access contextual information like the current iteration's index and total length.
```liquid
{% assign smoothie_flavors = "orange, strawberry, banana" | split: ", " %}
{% for flavor in smoothie_flavors -%}
{%- if forloop.length > 0 -%}
{{ flavor }}{% unless forloop.last %}-{% endunless -%}
{%- endif -%}
{% endfor %}
```
--------------------------------
### Slice a String by Start Index and Length
Source: https://shopify.github.io/liquid/filters/slice
Extracts a substring from a string starting at the specified index with a given length.
```liquid
{{ "Liquid" | slice: 2, 5 }}
```
--------------------------------
### Displaying Page Title with Object
Source: https://shopify.github.io/liquid/basics/introduction
Use objects enclosed in double curly braces to display dynamic content. This example shows how to render the page's title.
```Liquid
{{ page.title }}
```
--------------------------------
### Chaining Filters for Output Modification
Source: https://shopify.github.io/liquid/basics/introduction
Multiple filters can be applied sequentially to modify output. Filters are applied from left to right. This example capitalizes a string and then prepends text.
```Liquid
{{ "adam!" | capitalize | prepend: "Hello " }}
```
--------------------------------
### tablerow with offset parameter
Source: https://shopify.github.io/liquid/tags/iteration
Starts the tablerow loop after a specific index. Useful for skipping initial items or implementing pagination.
```liquid
{% tablerow product in collection.products cols:2 offset:3 %}
{{ product.title }}
{% endtablerow %}
```
--------------------------------
### Slice a String by Start Index
Source: https://shopify.github.io/liquid/filters/slice
Extracts a single character from a string starting at the specified index.
```liquid
{{ "Liquid" | slice: 0 }}
```
--------------------------------
### Slice an Array by Start Index and Length
Source: https://shopify.github.io/liquid/filters/slice
Extracts a range of elements from an array starting at the specified index with a given length.
```liquid
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
{{ beatles | slice: 1, 2 }}
```
--------------------------------
### Get First Word of a String
Source: https://shopify.github.io/liquid/filters/first
Demonstrates using the 'first' filter to extract the first word from a string after splitting it by spaces.
```liquid
{{ "Ground control to Major Tom." | split: " " | first }}
```
--------------------------------
### Slice a String by Start Index (Different Index)
Source: https://shopify.github.io/liquid/filters/slice
Extracts a single character from a string starting at a different specified index.
```liquid
{{ "Liquid" | slice: 2 }}
```
--------------------------------
### Slice a String with Negative Start Index
Source: https://shopify.github.io/liquid/filters/slice
Extracts a substring from a string using a negative start index, counting from the end of the string.
```liquid
{{ "Liquid" | slice: -3, 2 }}
```
--------------------------------
### Accessing Specific Array Items
Source: https://shopify.github.io/liquid/basics/types
Access array elements by their index using square brackets `[]`. Indexing starts at 0, and negative indices count from the end.
```liquid
{{ site.users[0] }}
{{ site.users[1] }}
{{ site.users[-1] }}
```
--------------------------------
### Using rstrip to remove trailing whitespace
Source: https://shopify.github.io/liquid/filters/rstrip
This example demonstrates how the rstrip filter removes trailing whitespace from a string. It preserves spaces within the string itself.
```Liquid
{{ " So much room for activities " | rstrip }}!
```
--------------------------------
### Get String Length with size Filter
Source: https://shopify.github.io/liquid/filters/size
Returns the number of characters in a string. This is useful for displaying character counts or enforcing string length limits.
```Liquid
{{ "Ground control to Major Tom." | size }}
```
--------------------------------
### Get Current Generation Time
Source: https://shopify.github.io/liquid/filters/date
Use the special keywords 'now' or 'today' with the 'date' filter to display the timestamp of when the page was last generated. Note that this is not the real-time user's current time if caching or static generation is involved.
```liquid
This page was last updated at {{ "now" | date: "%Y-%m-%d %H:%M" }}.
```
--------------------------------
### Get Array Length with size Filter
Source: https://shopify.github.io/liquid/filters/size
Returns the number of items in an array. This is commonly used to check the quantity of elements before processing or displaying them.
```Liquid
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array.size }}
```
--------------------------------
### Get Last Word of a String
Source: https://shopify.github.io/liquid/filters/last
Demonstrates using the 'last' filter to extract the last word from a string after splitting it into an array of words.
```liquid
{{ "Ground control to Major Tom." | split: " " | last }}
```
--------------------------------
### Appending to a URL with Filter
Source: https://shopify.github.io/liquid/basics/introduction
Filters modify the output of Liquid objects or variables. Use a pipe character `|` to separate the object from the filter. This example appends a string to a URL.
```Liquid
{{ "/my/fancy/url" | append: ".html" }}
```
--------------------------------
### Liquid Inline Comment Tag
Source: https://shopify.github.io/liquid/tags/template
Use inline comments starting with `#` within `{% %}` delimiters to prevent specific expressions or lines from rendering. Multi-line inline comments require `#` on each line.
```liquid
{% # for i in (1..3) -%}
{{ i }}
{% # endfor %}
{%
###############################
# This is a comment
# across multiple lines
###############################
%}
```
--------------------------------
### Basic Integer Division with divided_by
Source: https://shopify.github.io/liquid/filters/divided_by
Demonstrates basic division where the result is rounded down to the nearest integer when the divisor is an integer.
```liquid
{{ 16 | divided_by: 4 }}
{{ 5 | divided_by: 3 }}
```
--------------------------------
### Using at_least Filter
Source: https://shopify.github.io/liquid/filters/at_least
Demonstrates how the at_least filter enforces a minimum value. If the input is less than the specified minimum, the minimum is output. Otherwise, the original input is output.
```liquid
{{ 4 | at_least: 5 }}
{{ 4 | at_least: 3 }}
```
--------------------------------
### Using default filter with allow_false parameter
Source: https://shopify.github.io/liquid/filters/default
Explains how to use the 'allow_false' parameter to permit 'false' as a valid value instead of triggering the default.
```liquid
{% assign display_price = false %}
{{ display_price | default: true, allow_false: true }}
```
--------------------------------
### Order of Operations with AND and OR
Source: https://shopify.github.io/liquid/basics/operators
Demonstrates Liquid's right-to-left order of operations for logical operators. Parentheses are not supported and will cause errors.
```liquid
{% if true or false and false %}
This evaluates to true, since the `and` condition is checked first.
{% endif %}
```
--------------------------------
### Strip Whitespace Before and After Tags (With Control)
Source: https://shopify.github.io/liquid/basics/whitespace
Demonstrates effective whitespace control by applying hyphens to all tag delimiters, resulting in cleaner output.
```liquid
{% assign username = "John G. Chalmers-Smith" -%}
{%- if username and username.size > 10 -%}
Wow, {{ username -}} , you have a long name!
{%- else -%}
Hello there!
{%- endif %}
```
--------------------------------
### Basic tablerow Usage
Source: https://shopify.github.io/liquid/tags/iteration
Generates an HTML table with default row and column settings. Must be wrapped in opening and closing
tags.
```liquid
{% tablerow product in collection.products %}
{{ product.title }}
{% endtablerow %}
```
--------------------------------
### Reverse a String in Liquid by Splitting and Joining
Source: https://shopify.github.io/liquid/filters/reverse
Shows how to reverse a string by first splitting it into an array of characters, reversing the array, and then joining the characters back into a string. This is a common workaround as 'reverse' does not directly support strings.
```liquid
{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }}
```
--------------------------------
### Default Whitespace Behavior
Source: https://shopify.github.io/liquid/basics/whitespace
Demonstrates the default behavior where Liquid tags can introduce blank lines in the rendered output.
```liquid
{% assign my_variable = "tomato" %}
{{ my_variable }}
```
--------------------------------
### Using the Modulo Filter
Source: https://shopify.github.io/liquid/filters/modulo
Demonstrates the usage of the modulo filter with different numerical inputs. The filter calculates the remainder after dividing the first operand by the second.
```liquid
{{ 3 | modulo: 2 }}
{{ 24 | modulo: 7 }}
{{ 183.357 | modulo: 12 }}
```
--------------------------------
### Basic for loop
Source: https://shopify.github.io/liquid/tags/iteration
Repeatedly executes a block of code for each item in a collection. Refer to the `forloop` object for available attributes within the loop.
```liquid
{% for product in collection.products %}
{{ product.title }}
{% endfor %}
```
--------------------------------
### Float Division with divided_by
Source: https://shopify.github.io/liquid/filters/divided_by
Illustrates division where the divisor is a float, resulting in a float output.
```liquid
{{ 20 | divided_by: 7.0 }}
```
--------------------------------
### Create complex strings with capture and assign
Source: https://shopify.github.io/liquid/tags/variable
Combine 'assign' and 'capture' to build complex string variables using other variables.
```liquid
{% assign favorite_food = "pizza" %}
{% assign age = 35 %}
{% capture about_me %}
I am {{ age }} and my favorite food is {{ favorite_food }}.
{% endcapture %}
{{ about_me }}
```
--------------------------------
### Strip Whitespace Before and After Tags (No Control)
Source: https://shopify.github.io/liquid/basics/whitespace
Illustrates the default whitespace output when multiple tags and conditional logic are used without whitespace control.
```liquid
{% assign username = "John G. Chalmers-Smith" %}
{% if username and username.size > 10 %}
Wow, {{ username }} , you have a long name!
{% else %}
Hello there!
{% endif %}
```
--------------------------------
### Using the times filter
Source: https://shopify.github.io/liquid/filters/times
Demonstrates how to use the 'times' filter to multiply numbers. This filter takes one argument, the multiplier.
```liquid
{{ 3 | times: 2 }}
{{ 24 | times: 7 }}
{{ 183.357 | times: 12 }}
```
--------------------------------
### Using newline_to_br Filter
Source: https://shopify.github.io/liquid/filters/newline_to_br
Demonstrates how to use the newline_to_br filter to convert newlines in a string to HTML line breaks.
```liquid
{% capture string_with_newlines %}
Hello
there
{% endcapture %}
{{ string_with_newlines | newline_to_br }}
```
--------------------------------
### Capitalize a simple string
Source: https://shopify.github.io/liquid/filters/capitalize
Demonstrates the basic usage of the capitalize filter on a lowercase string.
```Liquid
{{ "title" | capitalize }}
```
--------------------------------
### Using at_most Filter
Source: https://shopify.github.io/liquid/filters/at_most
Demonstrates how the at_most filter caps a number at a specified maximum value. Use this filter when you need to ensure a value does not exceed a certain threshold.
```Liquid
{{ 4 | at_most: 5 }}
{{ 4 | at_most: 3 }}
```
--------------------------------
### Basic Equality Check
Source: https://shopify.github.io/liquid/basics/operators
Use the '==' operator to check if a product's title exactly matches a specific string.
```liquid
{% if product.title == "Awesome Shoes" %}
These shoes are awesome!
{% endif %}
```
--------------------------------
### Using default filter with undefined variable
Source: https://shopify.github.io/liquid/filters/default
Demonstrates the 'default' filter when the variable is not defined. The default value is displayed.
```liquid
{{ product_price | default: 2.99 }}
```
--------------------------------
### Joining Array Elements with a Separator
Source: https://shopify.github.io/liquid/filters/join
Demonstrates how to use the 'join' filter to combine elements of an array into a string, with ' and ' as the separator. The input array is first created using the 'split' filter.
```liquid
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
{{ beatles | join: " and " }}
```
--------------------------------
### Reverse an Array in Liquid
Source: https://shopify.github.io/liquid/filters/reverse
Demonstrates how to reverse the order of elements in an array using the 'reverse' filter. This is useful for displaying lists or sequences in reverse order.
```liquid
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array | reverse | join: ", " }}
```
--------------------------------
### Rounding Numbers with the 'round' Filter
Source: https://shopify.github.io/liquid/filters/round
Demonstrates how to use the 'round' filter to round numbers to the nearest integer or to a specific number of decimal places.
```liquid
{{ 1.2 | round }}
{{ 2.7 | round }}
{{ 183.357 | round: 2 }}
```
--------------------------------
### Initializing Arrays with Split Filter
Source: https://shopify.github.io/liquid/basics/types
While arrays cannot be initialized directly with Liquid, the `split` filter can create an array by dividing a string into substrings.
```liquid
{% assign my_array = "one,two,three" | split: "," %}
```
--------------------------------
### Liquid Render Tag with Parameters
Source: https://shopify.github.io/liquid/tags/template
Pass variables to a rendered template by listing them as parameters on the `render` tag. Multiple variables can be passed.
```liquid
{% assign my_variable = "apples" %}
{% render "name", my_variable: my_variable, my_other_variable: "oranges" %}
```
```liquid
{% assign featured_product = all_products["product_handle"] %}
{% render "product", product: featured_product %}
```
--------------------------------
### Basic cycle tag
Source: https://shopify.github.io/liquid/tags/iteration
Loops through a group of strings, printing them in order. Each call to `cycle` prints the next argument. Must be used within a `for` loop block.
```liquid
{% cycle "one", "two", "three" %}
{% cycle "one", "two", "three" %}
{% cycle "one", "two", "three" %}
{% cycle "one", "two", "three" %}
```
--------------------------------
### Integer Division with divided_by
Source: https://shopify.github.io/liquid/filters/divided_by
Shows integer division where the result is rounded down to the nearest integer.
```liquid
{{ 20 | divided_by: 7 }}
```
--------------------------------
### Access First Element of an Array
Source: https://shopify.github.io/liquid/filters/first
Shows how to assign an array to a variable and then access its first element using the 'first' filter.
```liquid
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
{{ my_array.first }}
```
--------------------------------
### Subtracting Numbers with the minus Filter
Source: https://shopify.github.io/liquid/filters/minus
Demonstrates the usage of the 'minus' filter to subtract integers and floating-point numbers.
```Liquid
{{ 4 | minus: 2 }}
{{ 16 | minus: 4 }}
{{ 183.357 | minus: 12 }}
```
--------------------------------
### Assigning Number Variables
Source: https://shopify.github.io/liquid/basics/types
Declare integer and float number variables using the `assign` tag.
```liquid
{% assign my_int = 25 %}
{% assign my_float = -39.756 %}
```
--------------------------------
### Outputting Nil Value
Source: https://shopify.github.io/liquid/basics/types
Tags or outputs that return `nil` will not print anything to the page. This demonstrates an empty output when `user.name` is nil.
```liquid
The current user is {{ user.name }}
```
--------------------------------
### Liquid Render Tag with 'with' and 'as'
Source: https://shopify.github.io/liquid/tags/template
Pass a single object to a template using the `with` and optional `as` parameters. The variable name in the rendered template is specified by `as`.
```liquid
{% assign featured_product = all_products["product_handle"] %}
{% render "product" with featured_product as product %}
```
--------------------------------
### Use size with Dot Notation in Tags
Source: https://shopify.github.io/liquid/filters/size
Demonstrates using the 'size' filter with dot notation within a conditional tag. This allows for dynamic logic based on the size of collections like site pages.
```Liquid
{% if site.pages.size > 10 %}
This is a big website!
{% endif %}
```
--------------------------------
### Switch Statement with case and when Tags
Source: https://shopify.github.io/liquid/tags/control-flow
The 'case' and 'when' tags create a switch statement for executing code based on specific variable values. 'when' can handle multiple values separated by commas or 'or'. An optional 'else' handles unmatched cases.
```Liquid
{% assign handle = "cake" %}
{% case handle %}
{% when "cake" %}
This is a cake
{% when "cookie", "biscuit" %}
This is a cookie
{% else %}
This is not a cake nor a cookie
{% endcase %}
```
--------------------------------
### Prepend a Variable
Source: https://shopify.github.io/liquid/filters/prepend
Concatenates a variable's value to the beginning of a string. Ensure the variable is assigned before use.
```Liquid
{% assign url = "example.com" %}
{{ "/index.html" | prepend: url }}
```
--------------------------------
### Rounding Up Numbers with ceil
Source: https://shopify.github.io/liquid/filters/ceil
Demonstrates the ceil filter with various decimal inputs. Liquid attempts to convert the input to a number before applying the filter.
```liquid
{{ 1.2 | ceil }}
{{ 2.0 | ceil }}
{{ 183.357 | ceil }}
```
--------------------------------
### Prepend a Literal String
Source: https://shopify.github.io/liquid/filters/prepend
Adds a literal string to the beginning of another literal string. This is useful for prefixing text.
```Liquid
{{ "apples, oranges, and bananas" | prepend: "Some fruit: " }}
```
--------------------------------
### Capture content into a string variable
Source: https://shopify.github.io/liquid/tags/variable
Use the 'capture' tag to capture the string content between the opening and closing tags and assign it to a variable. Variables created with 'capture' are always strings.
```liquid
{% capture my_variable %}I am being captured.{% endcapture %}
{{ my_variable }}
```
--------------------------------
### Mapping and Displaying Array with Nil Values
Source: https://shopify.github.io/liquid/filters/compact
This snippet demonstrates mapping an attribute from an array of objects and then iterating through the resulting array, which may contain `nil` values.
```liquid
{% assign site_categories = site.pages | map: "category" %}
{% for category in site_categories %}
- {{ category }}
{% endfor %}
```
--------------------------------
### Using default filter with empty variable
Source: https://shopify.github.io/liquid/filters/default
Illustrates the 'default' filter when the variable is explicitly set to an empty string. The default value is used.
```liquid
{% assign product_price = "" %}
{{ product_price | default: 2.99 }}
```
--------------------------------
### for loop with limit parameter
Source: https://shopify.github.io/liquid/tags/iteration
Limits the loop to a specified number of iterations. The `limit` parameter controls how many items are processed.
```liquid
{% for item in array limit:2 %}
{{ item }}
{% endfor %}
```
--------------------------------
### Multi-Condition Branching with elsif and else
Source: https://shopify.github.io/liquid/tags/control-flow
Use 'elsif' and 'else' within an 'if' or 'unless' block to handle multiple conditions. This allows for more complex conditional logic, executing different code blocks based on a sequence of checks.
```Liquid
{% if customer.name == "kevin" %}
Hey Kevin!
{% elsif customer.name == "anonymous" %}
Hey Anonymous!
{% else %}
Hi Stranger!
{% endif %}
```
--------------------------------
### Liquid Render Tag with 'for' and 'as'
Source: https://shopify.github.io/liquid/tags/template
Render a template multiple times for each item in an enumerable object using `for` and `as`. The `forloop` object is available within the rendered template.
```liquid
{% assign variants = product.variants %}
{% render "product_variant" for variants as variant %}
```
--------------------------------
### for loop with else clause
Source: https://shopify.github.io/liquid/tags/iteration
Specifies a fallback case that runs if the loop has zero iterations, typically when the collection is empty.
```liquid
{% for product in collection.products %}
{{ product.title }}
{% else %}
The collection is empty.
{% endfor %}
```
--------------------------------
### Using split to create an array from a string
Source: https://shopify.github.io/liquid/filters/split
This snippet demonstrates how to use the split filter to convert a comma-separated string into a Liquid array. The loop then iterates over the array to display each element.
```liquid
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
{% for member in beatles %}
{{ member }}
{% endfor %}
```
--------------------------------
### String Replacement using 'replace' filter
Source: https://shopify.github.io/liquid/filters/replace
Replaces all instances of 'my' with 'your' in the input string.
```liquid
{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }}
```
--------------------------------
### Liquid Render Tag
Source: https://shopify.github.io/liquid/tags/template
Use the `render` tag to insert the processed content of another template file. The `.liquid` extension is not required.
```liquid
{% render "template-name" %}
```
--------------------------------
### Inverse Condition with if Tag
Source: https://shopify.github.io/liquid/tags/control-flow
Demonstrates how to achieve the functionality of an 'unless' tag using an 'if' tag with a negated condition. This can be used for alternative conditional logic.
```Liquid
{% if product.title != "Awesome Shoes" %}
These shoes are not awesome.
{% endif %}
```
--------------------------------
### Concatenate Multiple Arrays
Source: https://shopify.github.io/liquid/filters/concat
Demonstrates chaining multiple 'concat' filters to join more than two arrays. This allows for combining several lists sequentially into one comprehensive array.
```liquid
{% assign furniture = "chairs, tables, shelves" | split: ", " %}
{% assign everything = fruits | concat: vegetables | concat: furniture %}
{% for item in everything %}
- {{ item }}
{% endfor %}
```
--------------------------------
### Integer Division with a Variable
Source: https://shopify.github.io/liquid/filters/divided_by
Divides a number by an integer variable, resulting in an integer output.
```liquid
{% assign my_integer = 7 %}
{{ 20 | divided_by: my_integer }}
```
--------------------------------
### Rounding Up String Numbers with ceil
Source: https://shopify.github.io/liquid/filters/ceil
Shows how the ceil filter handles a string input that represents a number. Liquid converts the string to a number before rounding up.
```liquid
{{ "3.5" | ceil }}
```
--------------------------------
### Deprecated Liquid Include Tag
Source: https://shopify.github.io/liquid/tags/template
The `include` tag is deprecated and should be replaced with `render`. It inserts content from another template but allows variable access and overwriting, which can impact performance and maintainability.
```liquid
{% include "template-name" %}
```
--------------------------------
### Using default filter with defined variable
Source: https://shopify.github.io/liquid/filters/default
Shows the 'default' filter when the variable is already defined. The defined value is displayed, not the default.
```liquid
{% assign product_price = 4.99 %}
{{ product_price | default: 2.99 }}
```
--------------------------------
### Truncate String to 3 Words
Source: https://shopify.github.io/liquid/filters/truncatewords
Shortens the input string to the first 3 words and appends a default ellipsis.
```Liquid
{{ "Ground control to Major Tom." | truncatewords: 3 }}
```
--------------------------------
### Capitalize a mixed-case string
Source: https://shopify.github.io/liquid/filters/capitalize
Shows how the capitalize filter handles strings with mixed casing, converting subsequent characters to lowercase.
```Liquid
{{ "my GREAT title" | capitalize }}
```
--------------------------------
### Replace First Occurrence in a String
Source: https://shopify.github.io/liquid/filters/replace_first
Demonstrates the basic usage of the 'replace_first' filter to substitute the first instance of 'my' with 'your' in a given string.
```Liquid
{{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }}
```
--------------------------------
### Checking for Emptiness
Source: https://shopify.github.io/liquid/basics/types
Use the `unless` tag with the `empty` keyword to check if an object is empty. This applies to empty strings and empty arrays as well.
```liquid
{% unless pages == empty %}
{{ pages.frontpage.title }}
{{ pages.frontpage.content }}
{% endunless %}
```
--------------------------------
### Float Division with a Variable
Source: https://shopify.github.io/liquid/filters/divided_by
Converts an integer variable to a float using 'times' and then performs float division.
```liquid
{% assign my_integer = 7 %}
{% assign my_float = my_integer | times: 1.0 %}
{{ 20 | divided_by: my_float }}
```
--------------------------------
### Filter Products by Type using 'where'
Source: https://shopify.github.io/liquid/filters/where
Use the 'where' filter to create a new array containing only products of a specific type. This is useful for categorizing and displaying subsets of data.
```liquid
{% assign kitchen_products = products | where: "type", "kitchen" %}
```
--------------------------------
### Conditional Logic with If Tag
Source: https://shopify.github.io/liquid/basics/introduction
Tags create logic and control flow in templates. The `if` tag allows conditional rendering of content. It does not produce visible output itself.
```Liquid
{% if user %}
Hello {{ user.name }}!
{% endif %}
```
--------------------------------
### Find a Single Object using 'where' and 'first'
Source: https://shopify.github.io/liquid/filters/where
Combine the 'where' filter with the 'first' filter to retrieve a single object from an array that matches specific criteria. This is useful for displaying a featured item.
```liquid
{% assign new_shirt = products | where: "type", "shirt" | first %}
```
--------------------------------
### Remove Leading Whitespace with lstrip
Source: https://shopify.github.io/liquid/filters/lstrip
Demonstrates the basic usage of the lstrip filter to remove leading whitespace from a string. It preserves internal and trailing whitespace.
```Liquid
{{ " So much room for activities " | lstrip }}!
```
--------------------------------
### tablerow with limit parameter
Source: https://shopify.github.io/liquid/tags/iteration
Exits the tablerow loop after a specific index. Useful for paginating or displaying a subset of items.
```liquid
{% tablerow product in collection.products cols:2 limit:3 %}
{{ product.title }}
{% endtablerow %}
```
--------------------------------
### Use 'first' in Conditional Tag
Source: https://shopify.github.io/liquid/filters/first
Illustrates using the 'first' filter with dot notation within an 'if' tag to check the first element of an array.
```liquid
{% if my_array.first == "zebra" %}
Here comes a zebra!
{% endif %}
```
--------------------------------
### Multiple Comparisons with OR
Source: https://shopify.github.io/liquid/basics/operators
Use the 'or' operator to check if a product's type matches either of two specified strings.
```liquid
{% if product.type == "Shirt" or product.type == "Shoes" %}
This is a shirt or a pair of shoes.
{% endif %}
```
--------------------------------
### Assigning Boolean Variables
Source: https://shopify.github.io/liquid/basics/types
Declare boolean variables with `true` or `false` values using the `assign` tag. No quotes are needed.
```liquid
{% assign foo = true %}
{% assign bar = false %}
```
--------------------------------
### Adding Numbers with the plus Filter
Source: https://shopify.github.io/liquid/filters/plus
Use the 'plus' filter to add numbers. It accepts a single numeric argument.
```liquid
{{ 4 | plus: 2 }}
{{ 16 | plus: 4 }}
{{ 183.357 | plus: 12 }}
```
--------------------------------
### Append string literal to URL
Source: https://shopify.github.io/liquid/filters/append
Appends a literal string '.html' to a URL string.
```liquid
{{ "/my/fancy/url" | append: ".html" }}
```
--------------------------------
### Absolute value of negative and positive numbers
Source: https://shopify.github.io/liquid/filters/abs
Demonstrates the `abs` filter with both a negative and a positive integer.
```liquid
{{ -17 | abs }}
{{ 4 | abs }}
```
--------------------------------
### for loop with range
Source: https://shopify.github.io/liquid/tags/iteration
Defines a range of numbers to loop through. Ranges can be defined using literal numbers or variables.
```liquid
{% for i in (3..5) %}
{{ i }}
{% endfor %}
{% assign num = 4 %}
{% assign range = (1..num) %}
{% for i in range %}
{{ i }}
{% endfor %}
```
--------------------------------
### for loop with continue
Source: https://shopify.github.io/liquid/tags/iteration
Causes the loop to skip the current iteration and proceed to the next when the `continue` tag is encountered.
```liquid
{% for i in (1..5) %}
{% if i == 4 %}
{% continue %}
{% else %}
{{ i }}
{% endif %}
{% endfor %}
```
--------------------------------
### Format Article Published Date
Source: https://shopify.github.io/liquid/filters/date
Use this snippet to format the 'published_at' date of an article into a human-readable string. The output format is controlled by the strftime-like argument.
```liquid
{{ article.published_at | date: "%a, %b %d, %y" }}
```
--------------------------------
### Liquid liquid Tag for Concise Logic
Source: https://shopify.github.io/liquid/tags/template
The `liquid` tag allows grouping multiple Liquid tags within a single delimiter set for more concise code. Use `echo` to output data within these blocks.
```liquid
{% liquid
case section.blocks.size
when 1
assign column_size = ''
when 2
assign column_size = 'one-half'
when 3
assign column_size = 'one-third'
else
assign column_size = 'one-quarter'
endcase %}
```
--------------------------------
### Truthy String in Conditional
Source: https://shopify.github.io/liquid/basics/truthy-and-falsy
Demonstrates how a non-empty string is evaluated as truthy in an `if` condition.
```liquid
{% assign name = "Tobi" %}
{% if name %}
This text will always appear since "name" is defined.
{% endif %}
```
--------------------------------
### Summing Object Property Values
Source: https://shopify.github.io/liquid/filters/sum
Use the 'sum' filter with a property name argument to sum the values of that property across an array of objects. This is useful for aggregating data like quantities or prices.
```Liquid
{% assign total_quantity = collection.products | sum: "quantity" %}
{{ total_quantity }}
```
--------------------------------
### Remove First Substring with remove_first
Source: https://shopify.github.io/liquid/filters/remove_first
Demonstrates how to use the 'remove_first' filter to remove the first occurrence of 'rain' from a string. This filter is case-sensitive.
```Liquid
{{ "I strained to see the train through the rain" | remove_first: "rain" }}
```
--------------------------------
### tablerow with cols parameter
Source: https://shopify.github.io/liquid/tags/iteration
Defines the number of columns for the table rows. This controls how many items appear in each row.
```liquid
{% tablerow product in collection.products cols:2 %}
{{ product.title }}
{% endtablerow %}
```
--------------------------------
### Extracting 'category' property from site.pages
Source: https://shopify.github.io/liquid/filters/map
This snippet demonstrates how to use the 'map' filter to extract all 'category' values from the 'site.pages' object into a new array named 'all_categories'. It then iterates through this new array to display each category.
```liquid
{% assign all_categories = site.pages | map: "category" %}
{% for item in all_categories %}
- {{ item }}
{% endfor %}
```
--------------------------------
### Empty String in Conditional
Source: https://shopify.github.io/liquid/basics/truthy-and-falsy
Shows that even an empty string is considered truthy in Liquid, potentially creating empty HTML tags if the variable exists.
```liquid
{% if page.category %}
{{ page.category }}
{% endif %}
```
--------------------------------
### Handling EmptyDrop Objects
Source: https://shopify.github.io/liquid/basics/types
An EmptyDrop object is returned when accessing a non-existent object. You can assign these to variables.
```liquid
{% assign variable = "hello" %}
{% assign page_1 = pages[variable] %}
{% assign page_2 = pages["does-not-exist"] %}
{% assign page_3 = pages.this-handle-does-not-exist %}
```
--------------------------------
### Cycle tag with named groups
Source: https://shopify.github.io/liquid/tags/iteration
Allows multiple `cycle` blocks to be used in a template by assigning a name to each cycle group. If no name is supplied, multiple calls with the same parameters are considered one group.
```liquid
{% cycle "first": "one", "two", "three" %}
{% cycle "second": "one", "two", "three" %}
{% cycle "second": "one", "two", "three" %}
{% cycle "first": "one", "two", "three" %}
```
--------------------------------
### Mapping and Displaying Array with Nil Values Removed
Source: https://shopify.github.io/liquid/filters/compact
This snippet shows how to use the `compact` filter after mapping an attribute to remove any `nil` values from the resulting array before iteration.
```liquid
{% assign site_categories = site.pages | map: "category" | compact %}
{% for category in site_categories %}
- {{ category }}
{% endfor %}
```
--------------------------------
### Sort Array of Objects by Property
Source: https://shopify.github.io/liquid/filters/sort
Sorts an array of objects (e.g., products) based on the value of a specified property (e.g., 'price'). This is useful for displaying items in a specific order.
```liquid
{% assign products_by_price = collection.products | sort: "price" %}
{% for product in products_by_price %}
{{ product.title }}
{% endfor %}
```
--------------------------------
### Strip Whitespace After Tag
Source: https://shopify.github.io/liquid/basics/whitespace
Shows how to use a hyphen in the closing delimiter of an assign tag to remove trailing whitespace.
```liquid
{% assign my_variable = "tomato" -%}
{{ my_variable }}
```
--------------------------------
### Check for Substring Presence
Source: https://shopify.github.io/liquid/basics/operators
Use the 'contains' operator to determine if a product's title includes a specific substring.
```liquid
{% if product.title contains "Pack" %}
This product's title contains the word Pack.
{% endif %}
```
--------------------------------
### Assigning a String Variable
Source: https://shopify.github.io/liquid/basics/types
Use the `assign` tag to declare a string variable. Liquid does not interpret escape sequences.
```liquid
{% assign my_string = "Hello World!" %}
```
--------------------------------
### Conditional Execution with unless Tag
Source: https://shopify.github.io/liquid/tags/control-flow
The 'unless' tag executes a block of code when a condition evaluates to false. It's the inverse of the 'if' tag and useful for displaying content when a specific state is not met.
```Liquid
{% unless product.title == "Awesome Shoes" %}
These shoes are not awesome.
{% endunless %}
```
--------------------------------
### Concatenate Two Arrays
Source: https://shopify.github.io/liquid/filters/concat
Joins two arrays, 'fruits' and 'vegetables', into a single array named 'everything'. This is useful when you need to combine distinct lists of items.
```liquid
{% assign fruits = "apples, oranges, peaches" | split: ", " %}
{% assign vegetables = "carrots, turnips, potatoes" | split: ", " %}
{% assign everything = fruits | concat: vegetables %}
{% for item in everything %}
- {{ item }}
{% endfor %}
```
--------------------------------
### Format Date String
Source: https://shopify.github.io/liquid/filters/date
The 'date' filter can also parse and format strings that contain well-formatted dates. This is useful for converting arbitrary date strings into a desired output format.
```liquid
{{ "March 14, 2016" | date: "%b %d, %y" }}
```
--------------------------------
### Summing Array Elements
Source: https://shopify.github.io/liquid/filters/sum
The 'sum' filter can be used without arguments to directly sum all the integer elements within an array. This is useful for simple aggregations of numerical data.
```Liquid
{% assign total_rating = article.ratings | sum %}
{{ total_rating }}
```
--------------------------------
### Append variable to string
Source: https://shopify.github.io/liquid/filters/append
Appends the content of a variable 'filename' to a base string. Ensure the variable is assigned before use.
```liquid
{% assign filename = "/index.html" %}
{{ "website.com" | append: filename }}
```
--------------------------------
### Case-insensitive sorting of strings
Source: https://shopify.github.io/liquid/filters/sort_natural
Sorts a simple array of strings in a case-insensitive manner. The output is joined back into a comma-separated string.
```liquid
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
{{ my_array | sort_natural | join: ", " }}
```
--------------------------------
### Rounding Down Numbers with floor
Source: https://shopify.github.io/liquid/filters/floor
Rounds down floating-point numbers to their nearest whole integer. The input is converted to a number before the filter is applied.
```liquid
{{ 1.2 | floor }}
{{ 2.0 | floor }}
{{ 183.357 | floor }}
```
--------------------------------
### Truncate String with Custom Ellipsis
Source: https://shopify.github.io/liquid/filters/truncatewords
Shortens the input string to 3 words and appends a custom string '--' as the ellipsis.
```Liquid
{{ "Ground control to Major Tom." | truncatewords: 3, "--" }}
```
--------------------------------
### Liquid Comment Tag
Source: https://shopify.github.io/liquid/tags/template
Use the `comment` tag to exclude blocks of code from rendering. Content within `{% comment %}` and `{% endcomment %}` is ignored.
```liquid
{% assign verb = "turned" %}
{% comment %}
{% assign verb = "converted" %}
{% endcomment %}
Anything you put between {% comment %} and {% endcomment %} tags
is {{ verb }} into a comment.
```
--------------------------------
### Convert string to uppercase
Source: https://shopify.github.io/liquid/filters/upcase
Use the 'upcase' filter to convert a string to all uppercase characters. It has no effect if the string is already in uppercase.
```liquid
{{ "Parker Moore" | upcase }}
```
--------------------------------
### Truncate String with No Ellipsis
Source: https://shopify.github.io/liquid/filters/truncatewords
Shortens the input string to 3 words without appending any trailing characters.
```Liquid
{{ "Ground control to Major Tom." | truncatewords: 3, "" }}
```
--------------------------------
### for loop with reversed parameter
Source: https://shopify.github.io/liquid/tags/iteration
Reverses the order of iteration for the loop. This flag is distinct from the `reverse` filter.
```liquid
{% for item in array reversed %}
{{ item }}
{% endfor %}
```
--------------------------------
### Sorting array of objects by a property
Source: https://shopify.github.io/liquid/filters/sort_natural
Sorts an array of product objects based on the 'company' property in a case-insensitive manner. This is useful for organizing collections by a specific attribute.
```liquid
{% assign products_by_company = collection.products | sort_natural: "company" %}
{% for product in products_by_company %}
{{ product.title }}
{% endfor %}
```
--------------------------------
### Filter Products by Truthy Property Value using 'where'
Source: https://shopify.github.io/liquid/filters/where
Filter an array to include only objects where a specified property has a truthy value. This is useful for checking boolean flags or the existence of a property.
```liquid
{% assign available_products = products | where: "available" %}
```
--------------------------------
### Convert String to Lowercase
Source: https://shopify.github.io/liquid/filters/downcase
Use the downcase filter to convert a string to all lowercase characters. This is useful for standardizing text.
```liquid
{{ "Parker Moore" | downcase }}
```
```text
parker moore
```
--------------------------------
### Handle already uppercase strings
Source: https://shopify.github.io/liquid/filters/upcase
The 'upcase' filter does not alter strings that are already entirely in uppercase.
```liquid
{{ "APPLE" | upcase }}
```
--------------------------------
### Truncate String with Custom Ellipsis
Source: https://shopify.github.io/liquid/filters/truncate
Shortens a string and appends a custom string. The length of the custom string counts against the total character limit.
```liquid
{{ "Ground control to Major Tom." | truncate: 25, ", and so on" }}
```
--------------------------------
### tablerow with range (variable number)
Source: https://shopify.github.io/liquid/tags/iteration
Loops through a range of numbers defined by a variable. The range is inclusive.
```liquid
{% assign num = 4 %}
{% tablerow i in (1..num) %}
{{ i }}
{% endtablerow %}
```
--------------------------------
### Sort Array Alphabetically
Source: https://shopify.github.io/liquid/filters/sort
Sorts a string array in case-sensitive alphabetical order. The input string is split into an array, sorted, and then joined back into a string.
```liquid
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
{{ my_array | sort | join: ", " }}
```
--------------------------------
### tablerow with range (literal number)
Source: https://shopify.github.io/liquid/tags/iteration
Loops through a range of numbers defined by literal values. The range is inclusive.
```liquid
{% tablerow i in (3..5) %}
{{ i }}
{% endtablerow %}
```
--------------------------------
### Increment vs Assign
Source: https://shopify.github.io/liquid/tags/variable
Variables created with 'increment' are independent of those created with 'assign'. 'increment' does not affect variables assigned a value directly.
```liquid
{% assign var = 10 %}
{% increment var %}
{% increment var %}
{% increment var %}
{{ var }}
```
--------------------------------
### URL-encode an email address
Source: https://shopify.github.io/liquid/filters/url_encode
Use url_encode to convert special characters in an email address to their percent-encoded form for safe URL usage.
```Liquid
{{ "john@liquid.com" | url_encode }}
```
--------------------------------
### Truncate String with No Ellipsis
Source: https://shopify.github.io/liquid/filters/truncate
Shortens a string to the exact character count without appending any trailing characters by passing an empty string as the second argument.
```liquid
{{ "Ground control to Major Tom." | truncate: 20, "" }}
```
--------------------------------
### Increment a number variable
Source: https://shopify.github.io/liquid/tags/variable
Use the 'increment' tag to create a new number variable initialized to 0. Subsequent calls increase its value by one.
```liquid
{% increment my_counter %}
{% increment my_counter %}
{% increment my_counter %}
```
--------------------------------
### Access Last Element of an Array
Source: https://shopify.github.io/liquid/filters/last
Shows how to access the last element of an array using dot notation after assigning an array to a variable.
```liquid
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
{{ my_array.last }}
```
--------------------------------
### Remove Leading and Trailing Whitespace
Source: https://shopify.github.io/liquid/filters/strip
Use the 'strip' filter to clean up strings by removing unnecessary whitespace from both ends. This is useful for normalizing user input or data from external sources.
```Liquid
{{ " So much room for activities " | strip }}!
```
--------------------------------
### Truncate String with Default Ellipsis
Source: https://shopify.github.io/liquid/filters/truncate
Shortens a string to a specified number of characters, appending '...' if the string is longer. The ellipsis is included in the character count.
```liquid
{{ "Ground control to Major Tom." | truncate: 20 }}
```
--------------------------------
### Liquid Raw Tag
Source: https://shopify.github.io/liquid/tags/template
Use the `raw` tag to temporarily disable Liquid tag processing. This is useful for including content with conflicting syntax, like Mustache or Handlebars.
```liquid
{% raw %}
In Handlebars, {{ this }} will be HTML-escaped, but {{{ that }}} will not.
{% endraw %}
```
--------------------------------
### Handle Already Escaped Strings
Source: https://shopify.github.io/liquid/filters/escape_once
Demonstrates that escape_once does not alter strings that already contain HTML entities. This prevents double-escaping.
```Liquid
{{ "1 < 2 & 3" | escape_once }}
```
--------------------------------
### Decrement vs Assign
Source: https://shopify.github.io/liquid/tags/variable
Variables created with 'decrement' are independent of those created with 'assign' or 'capture'. 'decrement' does not affect variables assigned a value directly.
```liquid
{% assign var = 10 %}
{% decrement var %}
{% decrement var %}
{% decrement var %}
{{ var }}
```
--------------------------------
### Decode URL-encoded String
Source: https://shopify.github.io/liquid/filters/url_decode
Use the url_decode filter to decode a string that contains URL-encoded characters and plus signs representing spaces.
```Liquid
{{ "%27Stop%21%27+said+Fred" | url_decode }}
```
--------------------------------
### String Already Lowercase
Source: https://shopify.github.io/liquid/filters/downcase
The downcase filter has no effect on strings that are already entirely in lowercase.
```liquid
{{ "apple" | downcase }}
```
```text
apple
```
--------------------------------
### Remove Duplicates from an Array
Source: https://shopify.github.io/liquid/filters/uniq
This snippet demonstrates how to use the 'uniq' filter to remove duplicate string elements from an array. The array is first created by splitting a string, and then 'uniq' is applied before joining the elements back into a string.
```liquid
{% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %}
{{ my_array | uniq | join: ", " }}
```
--------------------------------
### Rounding Down String Numbers with floor
Source: https://shopify.github.io/liquid/filters/floor
Rounds down a string that represents a number to its nearest whole integer. Liquid attempts to convert the string to a number before applying the filter.
```liquid
{{ "3.5" | floor }}
```
--------------------------------
### Liquid Inline Comment within liquid Tag
Source: https://shopify.github.io/liquid/tags/template
Inline comments (`#`) can be used within `{% liquid ... %}` blocks to comment out specific lines of Liquid code.
```liquid
{% liquid
# this is a comment
assign topic = 'Learning about comments!'
echo topic
%}
```
--------------------------------
### Decrement a number variable
Source: https://shopify.github.io/liquid/tags/variable
Use the 'decrement' tag to create a new number variable initialized to -1. Subsequent calls decrease its value by one.
```liquid
{% decrement variable %}
{% decrement variable %}
{% decrement variable %}
```
--------------------------------
### Conditional Check with Last Element
Source: https://shopify.github.io/liquid/filters/last
Illustrates using the 'last' filter with dot notation within an 'if' tag to perform a conditional check on the last element of an array.
```liquid
{% if my_array.last == "tiger" %}
There goes a tiger!
{% endif %}
```
--------------------------------
### Using replace_last filter
Source: https://shopify.github.io/liquid/filters/replace_last
Replaces the last occurrence of 'my' with 'your' in the given string.
```Liquid
{{ "Take my protein pills and put my helmet on" | replace_last: "my", "your" }}
```
--------------------------------
### for loop with break
Source: https://shopify.github.io/liquid/tags/iteration
Causes the loop to stop iterating prematurely when the `break` tag is encountered.
```liquid
{% for i in (1..5) %}
{% if i == 4 %}
{% break %}
{% else %}
{{ i }}
{% endif %}
{% endfor %}
```
--------------------------------
### Extract Year from Article Published Date
Source: https://shopify.github.io/liquid/filters/date
This snippet demonstrates how to extract just the year from an article's 'published_at' timestamp. It uses a specific format string to isolate the four-digit year.
```liquid
{{ article.published_at | date: "%Y" }}
```
--------------------------------
### tablerowloop object properties
Source: https://shopify.github.io/liquid/tags/iteration
Provides access to properties of the current iteration within a tablerow loop, such as index, row, and column information.
```json
{
"col": 1,
"col0": 0,
"col_first": true,
"col_last": false,
"first": true,
"index": 1,
"index0": 0,
"last": false,
"length": 5,
"rindex": 5,
"rindex0": 4,
"row": 1
}
```
--------------------------------
### Liquid Echo Tag within liquid Tag
Source: https://shopify.github.io/liquid/tags/template
The `echo` tag outputs an expression within `liquid` tags, supporting filters. It's equivalent to `{{ ... }}` but functional inside `liquid` blocks.
```liquid
{% liquid
for product in collection.products
echo product.title | capitalize
endfor %}
```
--------------------------------
### URL-encode a string with spaces
Source: https://shopify.github.io/liquid/filters/url_encode
The url_encode filter converts spaces into '+' signs, which is a common practice for URL encoding.
```Liquid
{{ "Tetsuro Takara" | url_encode }}
```
--------------------------------
### Remove HTML Tags with strip_html
Source: https://shopify.github.io/liquid/filters/strip_html
Use the strip_html filter to clean strings containing HTML markup. This is useful for displaying user-generated content or data from external sources without rendering HTML.
```Liquid
{{ "Have you read Ulysses?" | strip_html }}
```
--------------------------------
### Check for Array Element Presence
Source: https://shopify.github.io/liquid/basics/operators
Use the 'contains' operator to check if a specific string exists within an array of strings (e.g., product tags). Note: This operator only works for strings, not objects.
```liquid
{% if product.tags contains "Hello" %}
This product has been tagged with "Hello".
{% endif %}
```
--------------------------------
### Remove Newlines from a String
Source: https://shopify.github.io/liquid/filters/strip_newlines
This snippet demonstrates how to use the strip_newlines filter to remove all line breaks from a captured string. The filter is applied directly to the variable containing the text.
```liquid
{% capture string_with_newlines %}
Hello
there
{% endcapture %}
{{ string_with_newlines | strip_newlines }}
```
--------------------------------
### Escape Special Characters Once
Source: https://shopify.github.io/liquid/filters/escape_once
Use escape_once to convert special characters like '<' and '&' to their HTML entities. This filter will not re-escape entities that are already present in the string.
```Liquid
{{ "1 < 2 & 3" | escape_once }}
```
--------------------------------
### Escape Special Characters in a String
Source: https://shopify.github.io/liquid/filters/escape
Use the 'escape' filter to replace characters like apostrophes and ampersands with their HTML escape sequences. This is useful for safely embedding strings in URLs or HTML content.
```Liquid
{{ "Have you read 'James & the Giant Peach'?" | escape }}
```
--------------------------------
### Absolute value of a string containing a number
Source: https://shopify.github.io/liquid/filters/abs
Shows that the `abs` filter can process a string that contains a numeric value.
```liquid
{{ "-19.86" | abs }}
```
--------------------------------
### No Change for Strings Without Special Characters
Source: https://shopify.github.io/liquid/filters/escape
The 'escape' filter does not alter strings that do not contain characters requiring escaping, such as simple names.
```Liquid
{{ "Tetsuro Takara" | escape }}
```
--------------------------------
### Remove substring from string
Source: https://shopify.github.io/liquid/filters/remove
Removes all instances of the substring 'rain' from the input string. This filter is case-sensitive.
```Liquid
{{ "I strained to see the train through the rain" | remove: "rain" }}
```
--------------------------------
### Remove Last Substring Occurrence
Source: https://shopify.github.io/liquid/filters/remove_last
Use the 'remove_last' filter to remove the final instance of a substring from a string. This filter is case-sensitive.
```liquid
{{ "I strained to see the train through the rain" | remove_last: "rain" }}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.