HUBL in Javascript code




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

Thank you!


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 }}")
{% 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!


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



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.


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


Yep, that's possible!