CMS Development

Sandyv_
Member

How do I access a variable from my custom module, in a global JS file?

Hi,


I've already read a lot of posts about this, but can't seem to find one, that solves my problem or maybe I don't understand it correctly.

I want to access a field inside my custom module BEFORE it renders, from a global JS file. Is that possible?

Like use {{widget.name_of_module_field}} inside another JS file, so I can manipulate with it.

I have then read about export_to_template_context, but I'm not sure if that solves my problem? 

If so, read the following:
I've created a custom module where I want to set export_to_template_context to true, in a drag and drop template, but I don't know where to do so.

I understand that you can do this: 

{% module "name" module_id="id" label="label", export_to_template_context=true % }

But as I understand it, you can only do this, if you're coding the template in HTML+HubL whereas I'm using Hubspot drag and drop template. I might have misunderstood it. 

If this is not how, is there any other way?

0 Upvotes
1 Reply 1
tjoyce
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

How do I access a variable from my custom module, in a global JS file?

@Sandyv_

Unfortunately, no, HUBL is compiled on the server side whereas JS is on the client side. Perhaps you can take a step back and tell us what the ultimate functionality you are trying to achieve is, and we can help you come up with other creative solutions to get that task done. 


tim@belch.io