Use the Liquid slice filter when you need to display only part of an export value in a mailing, portal, dashboard, letter, or other Liquid-enabled context. For example, you can show the last four digits of an ID number or return a shorter version of a longer value.
🔔 Important!
Use
slicefor display formatting only. Do not use Liquid display changes as a security control for sensitive data. If users should not have access to the full value, do not expose the full value in that context.
⭐ Get Inspired
This article was adapted from a post by Technolutions staff in the Slate Community Forums' Get Inspired space. Have a great idea for a Get Inspired post? Let us know!
How the slice filter works
The slice filter returns a substring from a value. The first argument identifies the starting index. Liquid uses a zero-based index, so the first character is position 0.
For the word Slate, the index positions are:
S l a t e
0 1 2 3 4To return the first character, start at index 0:
{{"Slate" | slice: 0}}The output is:
STo return the last character, start at index 4:
{{"Slate" | slice: 4}}The output is:
eReturn multiple characters
Add a second argument to specify how many characters to return. This example starts at index 1 and returns four characters:
{{"Slate" | slice: 1, 4}}The output is:
lateReturn the last four characters of an export
Use a negative starting index to count backward from the end of the value. This pattern is useful when the export length can vary but you always need the final characters.
For an export named Student-ID, use:
{{Student-ID | slice: -4, 4}}If the export value is 0123456789, the output is:
6789You can include the filtered export in surrounding text:
Here are the last 4 digits of your student ID number: {{Student-ID | slice: -4, 4}}Chain slice with other filters
Liquid filters can be chained. For example, use prepend after slice to add characters before the displayed value:
{{Student-ID | slice: -4, 4 | prepend: "XXXXX"}}If the export value is 0123456789, the output is:
XXXXX6789Use a query formula instead
You can also return part of a value in the query that creates the export. Use this option when the shortened value should be available as a separate export, or when you want the transformation to happen before Liquid renders the output.
To return the last four characters, create a formula export that uses the RIGHT() function.

To return the first characters, use the LEFT() function or set the export field width, depending on the query output you need.

Choose between Liquid and a query formula
Option | Use when | Considerations |
|---|---|---|
Liquid | You only need to change how the value displays in one Liquid-enabled context. | The original export value is still available to the rendering context. |
Query formula | You want the shortened value to be its own export or reused in multiple outputs. | The formula must be built and maintained in the query. |