String contain question

Tourist
26 0 2

Hello!

 

I have a quick question. I have a string ",XS/S,M/L," and im trying to check if that string contains ","variant.title","  .

How can i do that ?

I tried like this : {% unless string contains ","variant.title"," %}

 

Thanks for your time ! :)

0 Likes
Navigator
1151 0 118

Do you need to check that the variant title is surrounded by commas?

{% unless string contains ","variant.title"," %}

By putting variant.title in quotes means that the text in the comparison is not the value of the variant's title but the actual text "variant.title".

http://www.StandoutDesigns.com ::: Solid Wood TV Furniture for Enthusiasts. Made in USA.
0 Likes
Tourist
26 0 2

Yes, i have, unless there is another way.

Like i said I have that string (,XS/S,M/L,) - what's between 2 commas is a variant.title and if i have another size M or S it won't work because my string contains M or S. That's why i'm trying to check if is surrounded by commas :)

 

0 Likes
Navigator
1151 0 118
{% assign myTarget = variant.title | prepend: "," | append: "," %}
{% unless string contains myTarget %}


Thanks, now I understand. So try the above. It assigns to a variable the variant title with a copy before and after.

http://www.StandoutDesigns.com ::: Solid Wood TV Furniture for Enthusiasts. Made in USA.
0 Likes
Explorer
112 1 19

Try this:

{% assign variant_title_with_commas = variant.title | append: ',' | prepend: ',' %}
{% unless string contains variant_title_with_commas %}

Do you want the unless code to run if string ",XS/S,M/L," equals exactly to variant.title ",XS/S,M/L," ? Still a bit confused as to what you want to do.

The easiest way to get Shopify help. Submit your task, get a quote, and we'll get the work done. Work with me at shupkeep.com
0 Likes
Tourist
26 0 2

Oh, that's why it didn't worked. I tried something like this :

{% assign myTarget =  append: "," | variant.title | append: "," %}

Now i understand why.

Thanks, it works. :)

0 Likes
Navigator
1151 0 118

Great! And, yes, filters are applied, left to right, in the order listed.

http://www.StandoutDesigns.com ::: Solid Wood TV Furniture for Enthusiasts. Made in USA.
0 Likes
Tourist
26 0 2

XS/S, M/L, S, L, M are different variant title from different products. I just wanted to display unique variants from my store so i can make a filter menu. 

Now the products that not contain the selected filter are transparent and blocked, i tried to hide them but is there anyway to achieve that without remaning a white space between products ?

0 Likes
Highlighted
Navigator
1151 0 118

Nice work!

http://www.StandoutDesigns.com ::: Solid Wood TV Furniture for Enthusiasts. Made in USA.
0 Likes
Tourist
26 0 2

Now the products that not contain the selected filter are transparent and blocked, i tried to hide them but is there anyway to achieve that without remaning a white space between products ?

0 Likes