Access to field from one custom module to another

Silent2000
Member

Hi. Can you suggest how resolve my problem? I make two custom HUBL+HTML modules. In one of them I have text field "clickerName" in which I put some value from visual editor. I want to access to this value from other custom module. Any suggestions?

P.S. I already try https://community.hubspot.com/t5/CMS-Development/Sharing-Macros-between-Modules/td-p/202892

and 

https://community.hubspot.com/t5/CMS-Development/How-do-I-access-the-value-of-a-choice-field-from-di...

but no luck

0 Upvotes
7 Replies 7
sharonlicari
Community Manager

Hi @Silent2000       

 

could you please share more context about the issue you are having? If you could share a screenshot will be perfect. With this information, our experts will be able to help. I will tag so they will be able to advise you.        

 

Hey @tjoyce @prosa @bschneidewind  could you please share your knowledge with @Silent2000 ?  

 

Thank you & Happy Friday

Sharon

 


¿Sabías que la Comunidad está disponible en Español?
¡Participa hoy en conversaciones en el idioma de tu preferencia,cambiando el idioma en tus configuraciones!

Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !


0 Upvotes
tjoyce
Recognized Expert | Platinum Partner

Hi @Silent2000 - Modules are meant to be descrete and it is not recommended that modules share information in that way. This helps modules get published in the marketplace be descrete and not have to have dependecies of other modules. 

 

If you would like to tell us what you're trying to accomplish, maybe we can help you with the approach instead of sharing data between modules.

 

tim@belch.io

Kevin-C
Recognized Expert | Partner

Hey @Silent2000 

 

This is my favorite question to answer because the usecases are so vast.

Also the answer is simple and well documented. A win-win!

 

Export to template context might be what you're looking for!

tjoyce
Recognized Expert | Platinum Partner

@Kevin-C - wouldn't you need to know the ID of the module to be able to traverse the  widget_data dict from another module? Wouldn't there be a lot of "hard-coded-ness" involved in that approach? I haven't used the export_to_template_context for anything other than HUBL templates so I'm excited to see your approach to the problem. 

 

Such a common question too.

Kevin-C
Recognized Expert | Partner

@tjoyce All valid and important points that would have to be taken into consideration when writing the modules. I may have over simplified my answer.

 

I also didn't investigate that sencond link, my apologies to all. “Wisely and slow; they stumble that run fast.” as was once wisely said lol.

Kevin-C
Recognized Expert | Partner

Hey again @Silent2000 

 

@amwilie recently answered another question and the solution might be something you could implement. She used HUBL to add data to a JS global, from which it can be used anywhere on the page.

 

Check it out here

 

@tjoyce thoughts?

0 Upvotes
albertsg
Participant

I know this converstation is some weeks old but I find it really interesting, so I wanted to share my experience with something similar in case it helps someone who sees this topic.

 

As you can see here https://community.hubspot.com/t5/CMS-Development/Refresh-module-list-when-loading-new-partial-templa... I tried to have different modules in partial templates and another "parent" module in the main template, then I wanted to share some data between modules/templates. All details in the previous URL.

 

From my experience, if the pages where you have the modules are somehow connected (loading partial templates from another template, for example), I would suggest using one "global module" in your main template so you can access the data from another partial template without the need of more modules. 

 

There are also other solutions to share data between templates, like using macros or a "config file" with a list of properties (for example in JSON format) and they might be more efficient, but this is completely up to you Smiley Happy