18 votes
1 answers
Remove comma if single metafield in Shopify Liquid
I'm struggling with remove the comma, when a single author is there for a book. What I want is Author1, Author
Below is my code
<a href="/collections/all/{{ product.metafields.text.author_1 | handleize }}">{{ product.metafields.text.author_1 }}</a>
{% for line_item in line_items %}
{
{% unless forloop.last %}
},
{% else %}
}
{% endunless %}
{% endfor %}
<a href="/collections/all/{{ product.metafields.text.author_2 | handleize }}">{{ product.metafields.text.author_2 }}</a>
Can you please help me with this
Undefined asked
453
votes
Answer
Solution:
Not sure to understand why this loop through line_items.
This should work (not tested):
{{ product.metafields.text.author_1 | strip }}{{ product.metafields.text.author_2 | prepend:', ' }}
Undefined answered
Source
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.