Skip to content
Log in

encrypt - Liquid Filter Reference

On this page

Description

Encrypts a value using symmetric encryption. The result can be decrypted using the decrypt filter with the same salt value. Supports String, Integer, Float, Boolean, Array, and Hash types. Encryption errors are logged to the Web Console rather than surfaced to the storefront.

Use this filter to safely pass state between Liquid templates — for example, storing values in hidden form fields, passing data through URLs, or sharing data between Liquid components without exposing the raw value.

Property Value
Return Type string
Error return nil (not an empty string)
Category text

Options

Option Description
salt An optional salt string used as part of the encryption key. Use the same salt value when decrypting. If omitted, the current session ID is used as the salt — the token is session-bound and cannot be decrypted in a different session.

Session-bound tokens

When salt is not provided, the token is encrypted using the current session ID as the implicit salt. This means:

  • The encrypted value can only be decrypted within the same session
  • If the same encrypted value is passed to a new session (for example, via a URL), decryption will fail
  • Use an explicit salt value when you need to decrypt across requests or sessions (for example, storing values in a database or passing them via email links)

Supported input types

The following input types can be encrypted and round-tripped through decrypt:

  • String
  • Integer
  • Float
  • Boolean (true / false)
  • Array
  • Hash

Examples

Encrypt a string:

liquid {{ "sensitive data" | encrypt }}

Encrypt with a salt:

liquid {{ "sensitive data" | encrypt: salt: "my-secret-salt" }}

Encrypt and immediately decrypt (round-trip):

liquid {% assign encrypted = "hello" | encrypt: salt: "my-salt" %} {{ encrypted | decrypt: salt: "my-salt" }}

Output: hello

Error handling

If encryption fails, the error is written to the Web Console and nil is returned (not an empty string — check for nil before using the result). The specific error message depends on the cause:

Cause Console message
No encryption salt configured No encryption salt found. Cannot encrypt or decrypt data.
Unsupported input type Decrypted token has unsupported type {type}

Check the Web Console when troubleshooting missing or nil encrypted values.

Was this article helpful?

Was this article helpful?