Escaping Characters in Liquid String

10,041

Solution 1

Typographically speaking, quotation marks are the wrong glyph to use to indicate feet and inches. Instead, you should use the prime () and double prime () symbols, respectively, and the multiplication sign (×) instead of "x":

{% assign tags = "4′ × 6′, 5′ × 8′, ..., 16″ × 16″ × 16″, 24″ × 36″, ..., rectangular, 55″ × 57″ with lip" | split: ',' %}

If you're set on using quotation marks, perhaps you can use HTML entities (I'm not sure if this works or not):

{% assign tags = "4'x6', ..., 16"x16"x16", 24"x36", 20"x32", ..." | split: ',' %}

Solution 2

In liquid you can escape them with \' \" etc but your application will probably escape the whole sequence. Instead use unicode:

{% assign tags = "4\2019 × 6\2019, 5\2019 × 8\2019, ..., 16\201D × 16\201D × 16\201D, 24\201D × 36\201D, ..., rectangular, 55\201D × 57\201D with lip" | split: ',' %}

For reference http://www.blooberry.com/indexdot/html/tagpages/entities/genpunctuation2.htm

I typically construct my whole template and then do replacements at the end:

{% capture escape_to_unicode %}{% assign tags = "4′ × 6′, 5′ × 8′, ..., 16″ × 16″ × 16″, 24″ × 36″, ..., rectangular, 55″ × 57″ with lip" | split: ',' %}{% endcapture %}{{ escape_to_unicode | replace: "‘", \2018 | replace: "’", \2019 | replace: '“', \201C | replace: '”', \201D }}

to boot: I'm pretty sick of people answering questions about escaping characters with typographical opinions. The reality is that there are contexts where you must use the "non-human" equivalent for humans. My example is typically in email html/css, I'm sure there must be other scenarios.

Share:
10,041
Andrew
Author by

Andrew

Updated on August 02, 2022

Comments

  • Andrew
    Andrew almost 2 years

    I am trying to put together a tag list that contains various sizes (in Shopify using Liquid). The sizes use single and double quotes for inches and feet. Because it uses both, it is causing issues with the string closing properly. I have tried using a standard escape character '\', but that doesn't seem to work. Is it possible to escape characters in Liquid or is there another method someone can recommend?

    {% assign tags = "4'x6', 5'x8', 8'x10', 9'x12', 10'x14', 5'x7', 3'x5', 2'x3', 6'x9', 16\"x16\"x16\", 24\"x36\", 20\"x32\", 20\"x48\", 20\"x72\", 42\"x48\" rectangular, 55\"x57\" with lip" | split: ',' %}