APIs & Integrations

TomekR
Participant

Passing data between modules used in the same template, global variables

Hey,
I would like a custom module to set a variable that would be visible for whole template that is using the module.

Example:

  1. A custom module with Google Maps element including all the data for the map
  2. Another custom module that creates a Google Map element
  3. A template calling one or multiple custom modules with Google Maps elements
  4. A template without any of those modules
  5. A partial (footer) that is included in every template with JS code that calls Google Maps API and JS init function

What I would like to achieve is to have the JS code for Google Maps only when module that creates a map element is used in the template. Any ideas?

I thought that setting a variable inside the map module that the footer can detect would be perfect, but of course the variable is not visible outside the module.

0 Upvotes
4 Replies 4
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Passing data between modules used in the same template, global variables

Hi @TomekR,

You should be able to export the variable to the template context, making it accessible throughout the template:

0 Upvotes
TomekR
Participant

Passing data between modules used in the same template, global variables

It does not really work for custom modules.

When using the custom module in my template like this:
{% module "module_153363010948629" module_id="3490718" label="EDGE Map Big" export_to_template_context=True %}
the module dissapears from template preview and does not work at all.

0 Upvotes
TomekR
Participant

Passing data between modules used in the same template, global variables

Correction. The module exports data to context, but does not render at all.

0 Upvotes
TomekR
Participant

Passing data between modules used in the same template, global variables

omg... this behavior is in this parameters definition... :confused: . Really no option to have both: html rendering and retriving data?

0 Upvotes