HUBL in Javascript code

forms

#1

Hello,

I would just want to ask if executing HUBL code in javascript is possible?

Thank you!


#3

HI @ruanngabriel, what is your use-case here? You can certainly use HubL to inject values into a javascript function as long as this ends up being valid JS.

For a very simple example, if I want to log the value of my name to the console, I can do something like this:

{% set myName = "Connor" %}

{% if myName %}
<script type="text/javascript">
     console.log("{{ myName }}")
</script>
{% endif %}

Here are two screenshots that show this works:

Let me know if I'm misunderstanding you and I'd be happy to take a further look!


#4

How about vice-versa?
hubl code inside external javascript file?

Thanks!


#5

Hi @ruanngabriel external in what way? You attach a JS file hosted externally with HubL in it to a HubSpot hosted page? If so, no you cannot do that. You can write HubL inside of Design Manager hosted JS files, custom modules, and the head HTML/ footer HTML of pages/content settings but that is it.


#6

External JS hosted in HubSpot. Like I'm writing the code in Design Manager.


#7

Yep, that's possible!