0
votes

i've assigned a variable in liquid and can't figure out how to output the value in a {% cycle %}

was looking for the syntax on Google/Shopify cheatsheet/liquid Github wiki and can't seem to find anything that works

is this possible?

i was trying

    {% assign col_suffix = 50 %}

    {% for article in articles %}
        {% cycle 'row': '<div class="col-container>', '', '<div class="col-container>', '' %}
        {% cycle 'col': '<div class="col-{{ col_suffix }}"></div>', '<div class="col-{{ col_suffix }}"></div>' %}
        {% cycle 'row': '</div>', '', '</div>', '' %}
    {% endfor %}

or various combinations by splitting it on the quotes but no luck

any help is appreciated!

1

1 Answers

0
votes

You could capture the string in a variable first, and then use the variable in the cycle. For example:

{% assign col_suffix = 50 %}
{% capture div_with_col_suffix %}<div class="col-{{ col_suffix }}"></div>{% endcapture %}

{% for article in articles %}
    {% cycle ... %}
    {% cycle 'col': div_with_col_suffix, div_with_col_suffix %}
    {% cycle ... %}
{% endfor %}

Also note that if both your items in the cycle are the same (as they are in the code in your question), you really don't need a cycle at all:

{% assign col_suffix = 50 %}

{% for article in articles %}
    {% cycle ... %}
    <div class="col-{{ col_suffix }}"></div>
    {% cycle ... %}
{% endfor %}