How to escape {{ }} inside CSS and JS files?

zeshanshani
Member

I've included a JS vendors file that uses {{  }} brackets to regex search. This is the exact code:

 

e.replace(/{{(width|height)}}/g,t);

But the problem is that they are being removed by HUBL after the file is loaded on the front-end. 

 

What is the best way to escape those lines? Normally in coding, we use backslash for escaping purpose but it's not working for HUBL:

 

e.g., \{\{

 

Thanks in advance for your help. 

3 Replies 3
absolutions
Contributor

Hi,

 

I think this can work you if you can place this as a file not hardcoded.

 

Thanks

Ab

0 Upvotes
tjoyce
Recognized Expert | Platinum Partner

@zeshanshani -

I'm not sure if this is in the documentation but, you can use Jinja's "raw" blocks. Here's a test for you. You will see the console output is "hello" so, it successfully replaced the string "{{width}}"

<script>
  {% raw %}
  var e = "{{width}}";
  console.log(e.replace(/{{(width|height)}}/g,"hello"));
  {% endraw %}
</script>

If this answer helped, please, mark as solved 😄


tim@belch.io | forms.belch.io | Design your own Beautiful HubSpot Forms; No coding necessary.

 

Drop by and say Hi to me on slack.

JasonRosa
HubSpot Employee

@tjoyce yes you're spot on! Here is the documentation in the designer docs for reference.