Creating a list from a text input

Gentlemen,

I have a question, already sought for the answer but I’m perplexed by the result:

Code:

{% input company.custom.Varia.Onderwerpen as:text placeholder:'varia' %}

{% assign str_Varia_Onderwerpen = company.custom.Varia.Onderwerpen | strip %}

{% assign arr_Varia_Onderwerpen = str_Varia_Onderwerpen | split:'|' %}

{{arr_Varia_Onderwerpen.size}}

The aim here is to give in a structured (pipe-separated) string in company.custom.Varia.Onderwerpen (such as ‘subject A|subject B|subject C’) and to show this list in the output as follows:

  • subject A
  • subject B
  • subject C

If I do not derive the string ‘subject A|subject B|subject C’ from an input object, the splitting happens as I expect. However, the splitting on the pipe doesn’t work with an input object. What am I missing here?

Thanks!

Hi Bart

The pipe symbol | is something tricky in liquid. Using another symbol such as ; should do the trick.
I’m wondering however why’d you define subjects in an input? Because alternatively, on firm level, you can do it in the confirguration of a template and if you want it on company level, you could use a fori instead.

Kind regards
Sam

Hi Sam,

Thanks, it worked with another symbol (such as ;). The reason I’m doing this, is because it’s the easiest way to allow multiple inputs in a text input object. Otherwise, I’d have to define a fori-loop within a for-loop (which is itself derived from a |-separated string). Maybe it’s possible (do you have ideas here?), but this (less elegant I admit) solution works for me.

Kind regards,

Bart.

Maybe this topic can help?

I just added an extra post at the bottom of that topic where I explain how you can nest a fori loop within a forloop.

Kind regards
Sam