Search code examples
google-apps-scripthandlebars.jsgoogle-cajaicanhaz.js

How do I make Caja preserve template text inside a script tag?


I was trying to see if I could use ICanHaz or Handlebars for building the sidebar of my Google Docs Add-on. However, it turns out Caja is stripping the actual HTML from my script tag. Is there any way to prevent this from happening?

Let's just say my Handlebars template would be this:

<script id="user" type="text/x-handlebars-template">
  <li>
    <p class="name">Hello I'm {{ name }}</p>
  </li>
</script>

Then currently, at runtime it's this:

<script id="user-caja-guest-0___" data-caja-type="text/x-handlebars-template"></script>

So, even though I'm able to look it up using $('#user").html(), it will just give me an empty template. Is there a way to prevent Caja from doing this?


Solution

  • Caja does not currently support preserving the content of <script> elements in any case, and also assumes that all script text is JavaScript. This would be possible, but nontrivial to support. If you need this feature, please file a request for it.