CMS Development

MaxHart
Member

Passing a variable as module property

I'm trying to loop through a posts topics and for each topic found, render an {% image %} module. However, the label and name of the module don't seem to accept variables as parameters. Does anyone know a workaround for this?

 

imageName is my variable, and i've tried with without wrapping it in curly braces.

 

Thanks in advance!

 

{% if content.topic_list %}
                
                    {% for topic in content.topic_list %}
                    
                    <div class="container">
                    
                        {% set imageName = 'Image'+loop.index %}
                        
                        <div class="twelve columns">
                        {% image {{ imageName }} label=imageName, alt="", src="http://fakeimg.pl/350x200/?text={{topic.slug}}&font=Open+Sans", width="100%" %}
                        </div>
                        {% set topic_posts = blog_recent_topic_posts(blogIDs[loop.index0], topic.slug, 3) %}
                        {% for topic_post in topic_posts %}{% unless topic_post.absolute_url == content.absolute_url %}<div style="background-color: #ddd; margin-bottom: 20px; padding: 20px 0;" class="four columns post-title">{{ topic_post.name }}</div>{% endunless %}{% endfor %}
                    
                        <div class="four columns"></div>
                    </div>
                    
                    {% endfor %}
                
                {% endif %}
0 Upvotes
1 Reply 1
mgrubbs
Participant

Passing a variable as module property

I have two potential solutions for you.

1) Have you tried adding parentheses around the brackets? ( I know, it's probably the first thing you tried but I think this may have worked for me before)

 

2) Use the unique_in_loop=True flag on the module ( There are some methods there that are being deprecated, but I doubt this part will be)

- Essentially, it lets you use your image modules in a loop but they won't end up overriding themselves with the same "Name" . So you could set the name = "featureImage" for example and if you had a loop of 10 feature images, they would each render in the modules list in the editor.

 

Hope that helps!

 

Best,

- Mike

 

0 Upvotes