Accessing Custom Module Data Fields from Blog Posts on Separate Page Template

Hi there, I am working on my first Hubspot project ever so my apologies if I am missing something major here! I’ve spent a fair amount of time in the docs and am just not making any progress. I want to emulate a custom post type for event data so I made a new blog called events and have a custom module (event_single_module) applied to the event blog template that collects data (time, location, etc) on each event. The purpose of the event blog is not to be seen on the site, but to store the information so it may be used in other front-end modules. This module is working just fine.

For viewing event data on the front end, I set up another custom module called event_picker_module. It takes a comma-delimited list of blog post IDs from the events blog, loops through, and gets details on each using the blog_post_by_id function. I have no problem getting a title from each blog post, so I know my loop is working okay. However, I am having trouble reaching and displaying the custom module data in the event_single_module for each post. I have read that getting data from a custom module within another template can be difficult and was able to find the unique custom module name in the JSON tree (module_153244861705268) and try that out (as is suggested here) with no success. It seems as though adding the export_to_template_context parameter to a module tag may be the missing link, but since I am troubleshooting within module files and not template files, I am not able to add a module tag without an error firing. Either that or I am just targeting incorrectly. Does anyone have ideas on how I can reach and use the event_single_module data in the event_picker_module? I will post the relevant code for each module below. Thank you very much for the help!

event_single_module

<div class="event-single">
 <div class="inner">
 <h2 class="event-title">{{ module.event_title }}</h2>

 <p class="date">
 {% if reoccurring %}
 	{{ module.reoccurring_date }}
 {% else %}
 	{{ module.event_date }}
 	{{ module.start_end_time }}
 {% endif %}
 </p> <!-- .date --> 

 <p class="location">{{ module.event_location }}</p>

 <p class="description">{{ module.event_description }}</p>

 {% if module.event_type_choice == 'eventbrite' %}
 	<a class ="eventbrite-link" href="{{ module.eventbrite_link }}">View on Eventbrite</a>
 {% elif module.event_type_choice == 'contact' %}
 	<a class ="contact-link" href="mailto:{{ module.contact_link }}">Contact Coordinator</a>
 {% endif %}

 </div>
</div><!-- .event-single -->

event_picker_module

{% for eblock in module.event_block %}
 	<div class="event-block">

 {% if eblock.event_block_title %}
 	<p class="event-block-title">{{ eblock.event_block_title }}</p>
 {% endif %}

 {% set events = eblock.event_ids %}
 <div class="event-table">
 	{% for id in events|split(',') %}
 	{% set current_event = blog_post_by_id(id) %}
 	 <div class="event">
 <p class="title">{{ current_event.title }}</p> 
 <!-- want to access custom module data for events here! --> 
 	 </div>
 {% endfor %}
 </div>

 	</div> <!-- .event-block -->
{% endfor %} 

@jellodemon - I recently answered a similar question here: https://community.hubspot.com/t5/Content-Design-Questions/Pulling-Article-Snippets/m-p/198249#M7004

I’m not sure if this works in your specific scenario of module to module but try looping through the widget data and matching the module name or id, then display the results. Some code that might help:

{% set current_event = blog_post_by_id(id) %}
{% for w in current_event.allWidgets %}
 {{w|pprint}}
{% endfor %}

if you get some kind of output there that resembles the data you want, we could continue to traverse the object to get the exact data you need.


If this answer helped, please, mark as solved :grinning_face_with_smiling_eyes:


tim@belch.io | forms.belch.io | Design your own Beautiful HubSpot Forms; No coding necessary.

Drop by and say Hi to me on slack.

@tjoyce data print worked like a charm and I was able to figure out the rest of the syntax from there
16x16_smiley-wink.png.png

Thank you so much for your help! Will mark as solved now.

@jellodemon - awesome, glad you got it working. And thank you for providing extensive detail in your question. You don’t see that too often (unless you’re used to the StackOverflow community) :grinning_face_with_smiling_eyes: