emailshopifyhtml-emailliquidliquid-template

Email Liquid Templates - Split string and show string[index] inline


I am currently working with liquid templates and I have a string that has a pipe delimiter |. How would I be able to split this string and display the specific string one I want?

I figured out how to split the string:

{{ "Cookies | Biscuits" | split: "|" }}

But I am unsure where to add the index of the string I need. For example, how can I get "Biscuits"?

Thanks


Solution

  • {{ "Cookies | Biscuits" | split: "|" | first | strip }} for Cookies

    {{ "Cookies | Biscuits" | split: "|" | last | strip }} for Biscuits

    or access it by index:

    {%- assign typeParts = "Cookies | Biscuits" | split: "|" -%}

    and then:
    {{ typeParts[0] | strip }} for Cookies
    {{ typeParts[1] | strip }} for Biscuits