Adding a custom value from a blog post template to a blog listing template

I created a custom blog post template that includes a custom module. I have also created a custom blog listing template. On the blog listing page, I would like to access an image that was added to the module, but it’s not one of the standard properties available on the blog object.

On the blog listing template, as I iterate over the content of plog posts, is there a way to get the image that I added to the post and use it on the blog listing page?

 <ul id="blogs">
 {% for content in contents %}
 <li class="post-item {% for topic in content.topic_list %}{{ topic.slug }}{% if not loop.last %} {% endif %}{% endfor %}"
 data-topics="{% for topic in content.topic_list %}{{ topic.slug }}{% if not loop.last %}, {% endif %}{% endfor %}">
 <div class="featured-image" style="background-image: url({{ content.featured_image }})"></div>
 <div class="post-title-wrapper">
 <h3 class="post-title">{{ content.name }}</h3>
 <a class="post-link" href="{{ content.absolute_url }}">Read Story <svg class="post-link-chevron" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 512"><path d="M17.525 36.465l-7.071 7.07c-4.686 4.686-4.686 12.284 0 16.971L205.947 256 10.454 451.494c-4.686 4.686-4.686 12.284 0 16.971l7.071 7.07c4.686 4.686 12.284 4.686 16.97 0l211.051-211.05c4.686-4.686 4.686-12.284 0-16.971L34.495 36.465c-4.686-4.687-12.284-4.687-16.97 0z"/></svg></a> 
 </div>
 </li>
 {% endfor %}
 </ul>

I’m an experienced developer, but new to HubSpot. I have gotten a lot of help from the support people, but this one they asked me ask over here.

Hi @JKeith ,

You can access the data of a module set on a blog post from a blog listing by using the following code:

{% for content in contents %}
 {% set my_blog_post_value = content.widgets.module_<module_id> %}
 {{ my_blog_post_value|pprint }}
{% endfor %}

The module ID should look something like this:

content.widgets.module_151618187561037

To check the contents of content.widgets you can use the following code inside your loop:

{{content.widgets|pprint}}

Is there a way to get repeater items using content.widgets? I have a custom module on a post thats a repeater, its a stats module. I need to bring those through to a featured posts on my listing page…

Hi @JKeith ,
You can try with this code:
<div class=“blog-index__post-image blog-index__post-image--large” {% if content.featured_image %} style=“background-image: url(‘{{ content.featured_image }}’);” {% endif %} >
</div>

Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.
Thanks and Regards.