Using of divisible


#1

Hello,

Im trying to use such code:

{% if loop.index0|divisible(widget.columns|int) %}

But im getting dividing by 0 error. widget.columns default value is set to 2.

Can anyone help?


#2

Hi @Michal_Golebiowski,

Can you send me a link to the page you’re working on? It sounds like widget.columns is somehow being set to 0, resulting in the divide by 0 error.


#3

Hello,
Here is the link to Design manager page preview: https://preview.hs-sites.com/_hcms/preview/template/multi?is_buffered_template_layout=true&portalId=335999&tc_deviceCategory=desktop&template_layout_id=5389520749
Default value is set to 0.


#4

Hi @Michal_Golebiowski,

I did a bit of testing, and I wasn’t able to reproduce any errors. Can you try setting widget.columns|int to a variable before putting it into the divisible() filter? I believe it might be a typecasting issue.


#5

Hello,
Belive me i have tried:
{% set clear_row = ‘’ %}
{% set cols = widget.columns|int +1 %}
{% if loop.index0|divisible(cols) %}
{% set clear_row = ‘clear-row’ %}
{% endif %}

Problem is that module is Saving, but not working properly. Missing some elemnts on Content Manager level. When i reached support they told me that because of errors in code module is not saving properly.

Nathalie Langlois 8 days ago

Hi Irvin,

I’ve been digging into the discrepancy we are seeing between the design manager preview of the Leadership List custom module and the page editor preview. While doing so, I noticed that the changes to the Leadership List module cannot be saved due to a syntax error on line 16.

From my testing, it appears that switching from a % to a / will resolve the error but I don’t have context of what this code is intended to do.

Do you mind reviewing the code and resolving the error so that we can publish the most recent changes to the custom module?

Thanks!

  • Nathalie
    Before that answer code looked like this:
    {% set clear_row = ‘’ %}
    {% if (loop.index0 % widget.columns|int) == 0 %}
    {% set clear_row = ‘clear-row’ %}
    {% endif %}
    Yo ucan stil lfind it in other custom module: People List
    They asked to replace Bold % with /. I simply wanted to have Modulo operator. According to spec http://designers.hubspot.com/docs/hubl/operators-and-expression-tests Its allowed to use %.
    But then we have error while saving…
    Przechwytywanie

#6

Hi @Michal_Golebiowski,

The modulo operator should definitely be supported, so if you’re getting an error there it sounds like it might be an issue on our end. I’ll touch base with the Support rep you’ve been working with; since this appears to be an issue on our end, it would be best to continue working through Support.


#7

Hello, Thank You!

So i should get back to supprt about this or wait for reply from You?


#8

Hi @Michal_Golebiowski,

I would recommend reaching back out to support. I touched base with the rep you were working with last, and I believe they’re still investigating this issue with product.


#9

Hello,
I found a simple solution that worked and i was able to save the custom module.
Added If widget.columns is > 0 condition…

                            {% set clear_row = '' %}
                            {% if widget.columns > 0 %}
                            {% if (loop.index0 % widget.columns|int) == 0 %}
                                {% set clear_row = 'clear-row' %}
                            {% endif %}
                            {% endif %}