I am creating a custom module combining two custom modules into one. I have an accordion module and I am trying to nest a module inside of it that can allow users to create an HTML table for displaying textual data (spec sheets, etc). I was able to get the table generator to work in a separate module, but when I pasted it into the nested group, it will show the paramters a user can select on the left, but won't display the HTML table it generates. I am stuck thinking it's the {% if item2.enable_data_table %} - can this item2 be used in multiple places? Should it be put in a string like the div class="content-block... etc"?
Please be gentle as I am relatively new to hubspot CMS and am pretty much self taught with this stuff so I don't really have a background in python, just HTML/CSS/some javascript.
So I wanted to make an update to this: I did a little studying and I also worked with another developer and it seems like the 'item2 item3' order needed to be rearranged. I'm attaching the final code where I got the code working.
However, now I have a new issue: The table repeater is nested inside of an accordion module. When 'enable data table' boolean is set to 'true', the accordion section that the table is inside of suddenly becomes a) not an accordion dropdown anymore, b) background of light grey, and c) suddenly left justified. It's very strange. Why would the data table affect items that are in the code above it?
@LVerner Since table_repeater is inside of the repeater_content group you'll want to change this piece of code :
{% for item in module.table_repeater %}
<tr class="{% cycle 'odd','even' %}">
{% for item2 in item.column_content_repeater %}
<td>{{ item2.table_column }}</td>
{% endfor %}
</tr>
{% endfor %}
to reference the repeater_content loop, by changing module.table_repeater to item2.table_repeater.
{% for row in item2.table_repeater %}
<tr class="{% cycle 'odd','even' %}">
{% for cell in table_row.column_content_repeater %}
<td>{{ cell.table_column }}</td>
{% endfor %}
</tr>
{% endfor %}
It's also helpful when writing multiple loops to use a variable name that reflects what the items are. (ex: content, repeater, row, cell) instead of using 'item', 'item2', and so forth. It makes it easier to tell what fields you're referencing.
If this answer solved your question, please mark it as the solution.
Thank you for your help! Do you just label those variables in the markup or is there a specific place on the right column to change them? I did name the groups and items I created. Part of this code was also taken from another module I did not create so I was just going with what was already in there - was afraid if I renamed something it would break it somewhere else.
@LVerner your content was accidentally marked as spam, so I have un-quarantined it for you. It's now live in the above ^^^ (Sometimes our system detects a content as spam when there are many codes in the reply, sorry for the incenvenience!)
So does that mean you managed to fix it? When you click on the little dots in the reply field, you should see a code option. If you paste your JSON there, it should stay in the reply.
Learn more about HubSpot by following me on LinkedIn or YouTube
✅ Did my answer solve your issue? Help the community by marking it as the solution.
@LVerner Could you start by checking the output of the fields you use in the if statements? The quickest way is to use the filter |pprint It will show you the output of the field, so you can check if your if statements are setup correctly.
So in your case, add the following in your for loop:
Did you use local development to create this module? If so, are you willing to share your fields.json? If you used the Design tools to create the module, you should see a 'Copy JSON' option to the left of the 'Add field' button. Could you share the JSON that way?
Learn more about HubSpot by following me on LinkedIn or YouTube
✅ Did my answer solve your issue? Help the community by marking it as the solution.
Hi, I'm trying to reply but it seems to be deleting the JSON fragment when I post.
I added the snippet in right after the 'for' statement, like so:
{% for item2 in item.repeater_content_row %}
{{item2.enable_data_table|pprint}}
When I preview the module, the text '(Boolean: {}) ' is now displayed in that area. After that I looked at my field group and noticed that there was another boolean field outside of the main group called 'expanded'.
Thank you so much for helping! I pasted the statement in that you asked and got "(Boolean: {}) " when I preview the page - Is there a specific place it needs to be pasted? I put it right after the 'for' statement like so:
{% for item2 in item.repeater_content_row %}
{{item2.enable_data_table|pprint}}
Here's the JSON snippet - hope this is what you need:
[{"default":true,"display":"checkbox","id":"5be095a7-b209-cb70-559b-a3886490f4b0","label":"Enable Module","locked":false,"name":"enable_module","required":false,"type":"boolean"},{"children":[{"allow_new_line":false,"default":"Features","id":"394ae6d1-9728-d2d3-cd5b-7a92347a8e4d","label":"Title","locked":false,"name":"title","required":false,"show_emoji_picker":false,"type":"text","validation_regex":""},{"children":[{"default":"<h5>Left Column Content</h5>\n<p>Insert content here</p>","id":"fc81745e-f945-96b7-9f3f-5ed9f91cd178","label":"Left Column Content","locked":false,"name":"left_column_content","required":false,"type":"richtext"},{"default":true,"display":"checkbox","id":"3cef579b-9046-0275-b8c6-f82f25346238","label":"Enable Right Column","locked":false,"name":"enable_right_column","required":false,"type":"boolean"},{"default":"<h5>Right Column Content</h5>\nInsert content here","id":"52c99f40-3847-a2f7-e613-013e7112de60","label":"Right Column Content","locked":false,"name":"right_column_content","required":false,"type":"richtext","visibility":{"controlling_field":"3cef579b-9046-0275-b8c6-f82f25346238","controlling_value_regex":"true","operator":"EQUAL"}},{"default":false,"display":"checkbox","id":"2ef48e70-0e3d-5c1a-b961-aefaefb8b259","label":"Enable Data Table","locked":false,"name":"enable_data_table","required":false,"type":"boolean"},{"children":[{"children":[{"allow_new_line":false,"default":"Row","id":"36be4b61-0146-f65a-75e2-5f3ed14718e4","label":"Heading","locked":false,"name":"heading","required":false,"show_emoji_picker":false,"type":"text","validation_regex":""}],"default":{"heading":"Row"},"expanded":false,"id":"52b2b643-ee74-628f-1b21-57b4b1cbe18f","label":"Table Title","locked":false,"name":"table_title","required":false,"tab":"CONTENT","type":"group"},{"children":[{"default":"<p>Add a new column here</p>","id":"bc49d2c4-f6f5-db68-0b7a-7000da3d613e","inline_help_text":"This will create a new column ","label":"Column","locked":false,"name":"table_column","required":false,"type":"richtext"}],"default":[{"table_column":"<p>Add a new column here</p>"}],"expanded":false,"id":"91a777ec-c9a2-3cac-e867-73c32da62d79","inline_help_text":"Must add one item for each column. So if you have 2 columns, you have to add 2 items to this row.","label":"Add Columns to Rows","locked":false,"name":"column_content_repeater","occurrence":{"default":1},"required":false,"tab":"CONTENT","type":"group"}],"default":[{"table_title":{"heading":"Row"},"column_content_repeater":[{"table_column":"<p>Add a new column here</p>"}]}],"expanded":false,"id":"4c688743-2a79-61ad-694c-0ba2485d6f19","inline_help_text":"Adding header columns is necessary to make rows underneath. ","label":"Add Columns in Title","locked":false,"name":"table_repeater","occurrence":{"default":1},"required":false,"tab":"CONTENT","type":"group"}],"default":[{"left_column_content":"<h5>Left Column Content</h5>\n<p>Insert content here</p>","enable_right_column":true,"right_column_content":"<h5>Right Column Content</h5>\nInsert content here","enable_data_table":false,"table_repeater":[{"responsive_data_table_text":"Add table title here.","table_title":{"heading":"Row"},"column_content_repeater":[{"table_column":"<p>Add a new column here</p>"}]}]}],"expanded":false,"id":"c0fb165f-fd46-ce69-35e5-2c0db319b8a8","label":"Repeater Content Row","locked":false,"name":"repeater_content_row","occurrence":{"default":1},"required":false,"tab":"CONTENT","type":"group"},{"default":false,"display":"checkbox","id":"24033a69-953b-0bb2-1e07-79e2f245cf0d","label":"Expanded","locked":false,"name":"expanded","required":false,"type":"boolean"}],"default":[{"title":"Features","repeater_content_row":[{"left_column_content":"<h5>Left Column Content</h5>\n<p>Insert content here</p>","enable_right_column":true,"right_column_content":"<h5>Right Column Content</h5>\nInsert content here","enable_data_table":false,"table_repeater":[{"responsive_data_table_text":"Add table title here.","table_title":{"heading":"Row"},"column_content_repeater":[{"table_column":"<p>Add a new column here</p>"}]}]}],"expanded":false}],"expanded":false,"id":"f5df3fe1-8e51-800d-f822-df1822d9c427","label":"Accordion Group","locked":false,"name":"accordion_group","occurrence":{"default":1,"sorting_label_field":"394ae6d1-9728-d2d3-cd5b-7a92347a8e4d"},"required":false,"tab":"CONTENT","type":"group"},{"children":[{"default":50,"display":"slider","id":"49f221cf-7450-518c-1fff-931516a6b923","label":"Desktop Top Padding","locked":false,"max":200,"min":0,"name":"desktop_top_padding","required":false,"step":10,"type":"number"},{"default":50,"display":"slider","id":"08dd9e6e-d9f0-18f4-ee6b-01d83f446b25","label":"Desktop Bottom Padding","locked":false,"max":200,"min":0,"name":"desktop_bottom_padding","required":false,"step":10,"type":"number"},{"default":50,"display":"slider","id":"9fd46656-8633-8491-452a-6fab7e4967be","label":"Mobile Top Padding","locked":false,"max":200,"min":0,"name":"mobile_top_padding","required":false,"step":10,"type":"number"},{"default":50,"display":"slider","id":"e97651bb-4384-76e0-5772-56700ff7e369","label":"Mobile Bottom Padding","locked":false,"max":200,"min":0,"name":"mobile_bottom_padding","required":false,"step":10,"type":"number"}],"default":{"desktop_top_padding":50,"desktop_bottom_padding":50,"mobile_top_padding":50,"mobile_bottom_padding":50},"expanded":false,"id":"ac3235dd-5fa3-ed72-4b2a-f4142bf36663","label":"Settings","locked":false,"name":"settings","required":false,"tab":"CONTENT","type":"group"}]