north.inhale
north.inhale

Reputation: 511

Comparison of the sign does not work in the liquid syntax

I am faced with a simple and boring error. The task to add a certain amount of charset value in line with a loop. However, liquid on the segment syntax refuses to do it.

{% assign text = 'Some example text here' %}  // Variable here
{% unless text.size < 100 %}                  // Start loop
    {% assign text = text | append: '#' %}    // Concate and iterate at the same time
{% endunless %}                               // End loop
                      
{{text}}                                      // Output value to screen

As the result I expect to see something like this: Some example text here###############################################################################

Please help!

Upvotes: 0

Views: 36

Answers (1)

Daut
Daut

Reputation: 2645

You cannot do a loop with Unless, Unless only fires once.

{% assign text = 'Some example text here' %}

{% for i in (1..100) -%}
    {% if i == text.size -%}
        {% break %}
    {% else -%}
        {% assign text = text | append: '#' %}
    {% endif -%}
{% endfor -%}
{{text}}

Upvotes: 1

Related Questions