Advantages of CoffeeScript When Working with jQuery Templates
bloggemdano.blogspot.com
bloggemdano.blogspot.com
Fetch the element using whatever, grab its innerHtml, and pass that string along to the templating library of your choice. The browser doesn't render the initial template markup because it's in a script tag, and it doesn't interpret it as javascript because of the non-standard type attribute. So for all intents and purposes it completely ignores it, but it's fully accessible for your use. Win-win.
That's not always efficient. Suppose you want the same lengthy template to be available across several pages which share the same JavaScript. Then it makes a lot more sense to put the template in the JS and serve it once than to put it in the DOM and serve it repeatedly. Also, with the DOM approach, you have to insert data into the template using regex rather than simple str1 + data + str2.
If syntax highlighting is really your major concern, write a simple script that compiles your .html to .coffee (sandwiched with """). Best of both worlds.
"Simple" str1 + data + str2 might fly for a trivial one to two page website, but quickly devolves into an unmaintainable mess of spaghetti code as project sizes increase. I don't know of any modern programmer that would ever advocate for string concatenation over string interpolation via sprintf/templating/etc. I should also hope you're not trying to parse the strings yourself manually, regex'ing variables into it. There are tons of fast and efficient template libraries to choose from instead.