Documentation Index

Fetch the complete documentation index at: https://knowledge.technolutions.net/llms.txt

Use this file to discover all available pages before exploring further.

Using the Slice Filter to Return Substrings of an Export

Prev Next

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 slice for 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 4

To return the first character, start at index 0:

{{"Slate" | slice: 0}}

The output is:

S

To return the last character, start at index 4:

{{"Slate" | slice: 4}}

The output is:

e

Return 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:

late

Return 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:

6789

You 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:

XXXXX6789

Liquid Markup Filters

Use 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.

Formula export using RIGHT to return the last four characters

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

Export settings for returning the first characters of a value

Choose between Liquid and a query formula

Option

Use when

Considerations

Liquid slice

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.

📖 Using Formulas in Queries

Still looking for what you need?