squirrellyjs / squirrelly

Semi-embedded JS template engine that supports helpers, filters, partials, and template inheritance. 4KB minzipped, written in TypeScript ⛺
https://squirrelly.js.org
MIT License
555 stars 81 forks source link

[docs] How to use in the browser? #229

Open coolaj86 opened 2 years ago

coolaj86 commented 2 years ago

I saw something about UMD support, but there's no snippet for what CDN to grab this from or how to use it in the browser (e.g. What's the name of the global?).

I'm expecting something like this:

Updated This works:

<script src="https://cdn.jsdelivr.net/npm/squirrelly@8.0.8/dist/browser/squirrelly.min.js"></script>
<script>
  window.Sqrl.render("Hi {{it.user}}", {user: "Ada Lovelace"})
</script>

Note to self:

  async function loadScript(src) {
    return await new Promise(function (resolve, reject) {
      var script = document.createElement('script');
      script.src =  src;
      //script.async = false;
      script.onload = resolve;
      script.onerror = reject;
      document.body.append(script);
    });
  }

  loadScript("https://cdn.jsdelivr.net/npm/squirrelly@8.0.8/dist/browser/squirrelly.min.js").then(function () {
    console.log("Loaded.");
  });