CMS Development

ocky_saktya
Member

Accessing Custom Module Field Value from another Custom Module

Hi,

 

I have a case that I need to accessing a value from a custom module, the scenario is like this:

1. I have a blog page, in that blog page I have "Event Information" module and "Related Events" Module

2. In the "Event Information" module there is a date field

3. My "Related Events" Module will list another blog page and need to display date field value in the "Event Information" module that used in another Blog Post

 

I'm new with this Hubspot CMS and HubL. I have tried this approach, but no luck,

Use "blog_recent_posts" and the iterate every post and call "content_by_id" but when I try to get the value using this:

{% set detail_post = content_by_id(rec_post.id) %}
{{detail_post.widgets.module_nnnn.date}}

the result always empty, I have ensure the module is correct but still no result.

I'm new to this Hubspot CMS so any kind of help will be very helpfull.

 

 

 

 

 

0 Upvotes
2 Replies 2
lscanlan
HubSpot Alumni
HubSpot Alumni

Accessing Custom Module Field Value from another Custom Module

Hi @ocky_saktya,

 

I'd probably have to see your specific module to understand why that's not working. But I have a few other ideas for you. You could try pretty printing the module data inside your blog_recent_posts() for loop. So you could do something like:

 

{% set rec_posts = blog_recent_posts(XXXX, 3) %}
{% for rec_post in rec_posts %}
	<p>{{ rec_post.widgets|pprint }}</p>
{% endfor %}

That way you could see if you're accessing the data using the right variable.

 

Another idea is to take a look at what I described here: https://community.hubspot.com/t5/Share-Your-Work/How-to-add-Featured-Video-functionality-to-a-blog/m.... The specific use-case was for adding a featured video instead of a featured image for blog posts. But the important concept is accessing module data, which should be possible inside another module. You could also apply this concept to within your recent posts loop. So instead of trying to access the specific module ID in the way that you're doing, you could do another loop through the post's modules, and then when you find the ID of the module you're looking for, you could grab the value inside that module. This would also prevent any kind of error for if a post doesn't have the module or value you're looking for.

 

I'm also happy to take a look at your module if you're still having trouble with it, so feel free to send it over here or in a direct message.

 

Leland Scanlan

HubSpot Developer Support
kaious
Top Contributor

Accessing Custom Module Field Value from another Custom Module

Thanks @lscanlan - I had the same question. That pretty print trick worked a treat Smiley Happy