1

How do I pass variables into the range filter from a static supertable field?

{% for item in variants.b2bProductQty %}

  {% set start = item.selectRange.cellStartInteger %}
  {% set end = item.selectRange.cellEndInteger %}
  {% set increment = item.selectRange.cellIncerement %}

  {% for i in range(start, end, increment) %}
     <option value="{{ variants.sku }}:">{{ i }}</option>
  {% endfor %}

{% endfor %}

This results in the error:

range(): Argument #3 ($step) must not exceed the specified range

When I hardcode the numbers from the field it works

{% for i in range(5, 50, 5) %}
   <option value="{{ variants.sku }}:">{{ i }}</option>
{% endfor %}

If I just print out {{ start }} it shows 5 just fine

1
  • could it be that you have a typo? "cellIncerement" instead of "cellIncrement" Commented Nov 3, 2023 at 13:34

2 Answers 2

1

I can't test easily because I never use Supertable, but my guess would be that if you were to dump out item.selectRange.cellStartInteger (DUMP out, not just print out - ie.{{ dump(item.selectRange.cellStartInteger) }}), you might find that it's a big complicated object rather than just a simple value. In that case, if it's anything like Craft's dropdown field you'll need to put .value on the end to get just the raw value.

2
  • You are correct. The dump outputs int(5) I switched back to regular integer fields but this outputs the same. How do I only get 5 ?
    – KSPR
    Commented Nov 3, 2023 at 18:24
  • Well, no... int(5) means I'm not correct here. It's not a big complicated object as I was guessing - this means it's a simple integer, as it should be. Commented Nov 4, 2023 at 21:55
1

The error was in the increment variable because it is optional. If there is no value it throws an error it shoudl default to 1

So I constructed it like this:

{% for item in variants.b2bProductQty %}

  {% set start = item.rangeStart %}
  {% set end = item.rangeEnd %}
  {% set increment = item.rangeInc ? item.rangeInc : 1 %} {# fallback to 1 #}
                                
  {% for i in range( item.rangeStart , item.rangeEnd, increment) %}
    <option value="{{ variants.sku }}:">{{ i }}</option>
  {% endfor %}
                                
{% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.