I’m trying to use the gallery inside a custom module, so I need to get the module ID to get the content.
I searched and found this solution:
https://community.hubspot.com/t5/Content-Design-Questions/Using-a-module-inside-a-custom-module/m-p/7399/highlight/true#M762
So I used it like this:
{% gallery "slider_gallery" label="Slider Gallery", export_to_template_context=True, no-wrapper=True %}
{% set gallery_caller = "{{widget_data" ~ "." ~ parent_custom_widget_name ~ "_slider_gallery" ~ ".slides}}" %}
{% for item in gallery_caller %}
<li class="side-img" {% if item.img_src %} style="background-image:url( {{ item.img_src }} )" {% endif %} ></li>
{% endfor %}
But I’m not able to use this string in a for statement
If I print the string, it’ll correctly print the gallery array. But if I use in a for statement, it throws me a warning:
Cannot resolve property ‘img_src’ in ‘{{widget_data.widget_1515267612447_slider_gallery.slides}}’
I have used this hack to achieve this. Use the set variable function to concatenate a string that includes the parent_custom_widget_name variable**.** The parent_custom_widget_name includes the appended number for the module instance on the page. Then use your custom variable where you want the content.
{% set string = "{{widget_data" ~ "." ~ parent_custom_widget_name ~ "_my_content" ~ ".value}}" %}
<p> {{string}} </p>
Wow, that’s clever. And it works!
How can I do that in a for loop?
{% gallery "slider_gallery" label="Slider Gallery", export_to_template_context=True, no-wrapper=True %}
{% set gallery_caller = "{{widget_data" ~ "." ~ parent_custom_widget_name ~ "_slider_gallery" ~ ".slides}}" %}
{% for item in gallery_caller %}
<li class="side-img" {% if item.img_src %} style="background-image:url( {{ item.img_src }} )" {% endif %} ></li>
{% endfor %}
It’s getting me a warning:
Cannot resolve property ‘img_src’ in ‘{{widget_data.widget_1515267612447_slider_gallery.slides}}’