Templating JS?

This sounds like a case of http://xyproblem.info .

You should not want to do this. JS files are code and combining code and templating leads to madness. Trust me from experience on this one, the results are instantly unreadable spaghetti.

So why do you want to do this? If you need some data in your JS, you should read in the data from the DOM. E.g., your HTML has <div data-site-url="{{ .Site.BaseURL }}"></div> and then using JS, you can pick up the data attribute. But in the case of the baseURL, it’s not clear why you wouldn’t just use window.location instead. Is your site not the domain root?

1 Like