Escaping Characters in Liquid String

断了今生、忘了曾经 提交于 2019-12-08 19:34:21

问题


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: ',' %}

回答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: ',' %}



回答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.



来源:https://stackoverflow.com/questions/32983352/escaping-characters-in-liquid-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!