CMS Development

vin-aws
Contributor

Module unique_in_loop inside nested for loop

SOLVE

Trying to create a table of columns and rows with rich text modules.

 

<div class="table-container">
    {% for i in range(widget.number_of_columns|int) %}
        <div class="col">
            <h1>{% rich_text "header" value="Header", label="Header", no_wrapper=True, unique_in_loop=True %}</h1>
            <h3>{% rich_text "price" value="$100", label="Price", no_wrapper=True, unique_in_loop=True %}</h3>
            {% for j in range(widget.number_of_rows|int) %}
                <div class="row">
                    {% rich_text "item" value="List Item", no_wrapper=True, unique_in_loop=True %}
                </div>
            {% endfor %}
        </div>
    {% endfor %}
</div>

Any way to make the inner row rich_texts unique? They are appearing as the same for each column.

1 Accepted solution
vin-aws
Solution
Contributor

Module unique_in_loop inside nested for loop

SOLVE

What I did to solve this problem was make each table column its own custom module and which looped and allowed user to enter number of rows. In the big table module itself it loops and allows user to pick number of columns which then inserts that number of custom modules of columns.

View solution in original post

0 Upvotes
3 Replies 3
tjoyce
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

Module unique_in_loop inside nested for loop

SOLVE

Good Question. I hate to say it's not possible but.... it's not possible to interpolate names in the HUBL module definitions. It's also not possible to pass anything other than boolean values to unique in loop. Perhaps you could run each loop without nesting them and then use javascript to move the elements into the correct places? I know that's a stretch but there are limited solutions.

 


tim@belch.io
0 Upvotes
vin-aws
Contributor

Module unique_in_loop inside nested for loop

SOLVE

Yeah I will probably have to move elements with javascript but even then my options are limited as I want the user to be able to choose the number of rows for each column...So somehow I still need a nested loop

vin-aws
Solution
Contributor

Module unique_in_loop inside nested for loop

SOLVE

What I did to solve this problem was make each table column its own custom module and which looped and allowed user to enter number of rows. In the big table module itself it loops and allows user to pick number of columns which then inserts that number of custom modules of columns.

0 Upvotes