I am trying to generate this output:
["index", "last", "first"]
from an inital (potentially empty) string:
{%- assign rels = link.rel -%}
and conditional additions to that string:
{%- if first -%}{%- assign rels = rels | append: ",first" -%}{%- endif -%}
{%- if last -%}{%- assign rels = rels | append: ",last" -%}{%- endif -%}
I am then splitting the rels
and try to remove empty items (not working)
`{%- assign rels = rels | split: “,” | compact -%}
And then I render it:
[
{% for rel in rels %}
"{{rel}}"
{% unless forloop.last %},{% endunless %}
{% endfor %}
]
I hope there is an easier, more compact way to do that?
Something like this would be nice:
[ {{ rels | split: "," | prepend: '"' | append: '"' }} ]