How to get all variants of option2 in option1

Hello

How to get the following output for option something like this (in one line):

S: Low Medium High

I followed this example but the output was not in one line

{% for variant in product.variants -%}
  {%- capture options -%}
    {% for option in variant.option2 -%}
      {{ option }}{%- unless forloop.last -%}/{%- endunless -%}
    {%- endfor %}
  {%- endcapture -%}
  
{{ variant.option1 | strip }}: {{ options | strip }}
{%- endfor %}

I approach checking my message and your help, Thank you in advance :folded_hands:

hello there

To output the options for a product’s variants in one line, you can modify the code you provided to remove the line breaks and whitespace between the options. Here’s an updated version of the code that should produce the desired output:

{% for variant in product.variants %}
  {% capture options %}
    {% for option in variant.options %}
      {{ option }}{% unless forloop.last %} {% endunless %}
    {% endfor %}
  {% endcapture %}
  
  {{ variant.title }}: {{ options | strip }}
{% endfor %}

This code will output the options for each variant in the format “Title: Option1 Option2 Option3”. The strip filter is used to remove any whitespace between the options.

I see, Thank you so much~ @EcomGraduates