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
599 stars 82 forks source link

Questions #102

Closed kokujin closed 5 years ago

kokujin commented 5 years ago
  1. Is it possible for templates to inherit from a layout template? ( Swig, Nunjucks e.t.c)
  2. Better/ More examples showing how to use partials?

You mentioned giving up on this thread, https://github.com/dondido/express-es6-template-engine/issues/11#issuecomment-388581032. Is this still the case?

Thanks

nebrelbug commented 5 years ago

Hi @kokujin, thanks for the questions! There's no default way for templates to inherit from a layout template, but it would be relatively easy to implement using helpers. Here's how a template could look after you registered two helpers:

{{use('somelayout')}}
  {{#header}}
  This will get put in the header section
  {{#content}}
  This will get put in the content section
{{/use}}

Then, your layout could look like this:

<html>
  <head>
    {{header}}
  </head>
  <body>
    {{content}}
  </body>
</html>

And the use helper could just render the layout template with the values of its blocks. That probably makes almost no sense 😄 so I'll create an example soon and share it with you.

  1. Here's an example of a template with partials: https://codepen.io/nebrelbug/pen/qLrpJx

I did mention giving up in that thread, but since then I have realized that Squirrelly has a lot of unique advantages. Plenty of people use Handlebars and Mustache for their simplicity, but Squirrelly is faster and more lightweight while being (I think) just as simple.

I think the real value of Squirrelly is in its simplicity and speed. As shown in this benchmark, it's one of the fastest template engines out there. However, it contains much less bloat than many other template engines I've seen; it gives you the tools and allows you to build on them.

I hope this helps! As I said, I'll put together an example project using layouts and inheritance soon 😃

kokujin commented 5 years ago

Happy holidays and thanks @nebrelbug.