CMS Development

JakeGarver
Participant

Issue pulling custom blog post fields within a recent posts module on a blog post template

Hi Everyone-

 

A client's website has an "Events" blog channel, with a custom module embedded on the template that provides the client with separate fields for the event location, time, registration link, etc.

On the blog listing page, we've updated the blog listing module to display those fields and it works perfectly.

However, when we paste that code into a related posts module that lives at the bottom of the blog post template, it only pulls the event data from the event post you're on, not for each related event.

So if you're on the page for Event 1, the custom field data for Events 2, 3 & 4 in the related post module will only show the data for Event 1. I've pasted the code below. Any help is appreciated.

 

{% if content.widgets.module_16619998651649.body.event_date_time %}
<strong>Date:</strong>
{{ datetimeformat(content.widgets.module_16619998651649.body.event_date_time,'%B %e, %Y') }}{% endif %}

0 Upvotes
2 Replies 2
JakeGarver
Participant

Issue pulling custom blog post fields within a recent posts module on a blog post template

Figured it out. For reference, we're using a child theme of Growth, and we've copied the Recent Posts module to the child theme. In the blog listing module, they used {% for content ... %} and the Recent Posts module used {% for post ... %} which is why the same code wasn't working.

 

Changed to this:

{% if post.widgets.module_16619998651649.body.event_date_time %}
<strong>Date:</strong>
{{ datetimeformat(post.widgets.module_16619998651649.body.event_date_time,'%B %e, %Y') }}

{% endif %}

0 Upvotes
Jaycee_Lewis
Community Manager
Community Manager

Issue pulling custom blog post fields within a recent posts module on a blog post template

Hey, @JakeGarver 👋 Did you get this resolved?

 

If not, can you share what your for loop looks like? Pseudocode example:

{% for related_post in related_posts %}
    <!-- Your related post code here -->
{% endfor %}

 

I wonder if there is a scope problem. Have you tried referencing your loop variable instead of the content variable?

 

It's hard to give a good guess without more information. 

 

Best,

Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot