Is it possible to escape }} within a replace filter in Liquid?

Viewed 14

i'm fairly new to learning Liquid and have not been able to find any documentation how to do to the below without throwing an error.

| replace: "]]", "}}"

Is there a way to escape the }} in this string as I'm sure this is the issue.

Thank you

1 Answers

You need to use {%- raw -%} {%- endraw -%} tag to use raw liquid curly braces without considering it as liquid.

and you need to assign it to a variable using {%- capture name_of_variable -%} {%- endcapture -%}

and then replace the "]]" with the captured_variable

{%- capture my_captured_sign -%}

{%- raw -%}}}{%- endraw -%}

{%- endcapture -%}

<h1>{{'hello]]world' | replace: "]]", my_captured_sign }}</h1>

take note: use the sign - with the tags, so it should be so you don't include white spaces.

take note: my_captured_sign will be added without the ""

Related