This is the second episode in a three part series on serving content from Koajs. In the first episode we looked at Jade, an excellent , unique and popular templating language. This week we’ll contrast Jade with a more more conventional choice: Swig.
Swig can be appealing for several reasons:
- It simply intermixes the templating syntax with html, which makes for a smaller learning curve when compared to Jade.
- It’s one of the fastest templating engines available in node.js. So if you can’t stand the thought of using anything but the fastest engine, swig may be for you.
- It offers simple extensibility so adding functionality is a breeze
We’ll continue to explore and learn by creating tests, which provides an excellent way to validate our assumptions, expectations and understanding.
Were going to focus on using swig in the context of a Koajs application, so well setup our tests to call a Koajs application that will render our swig templates and return the resulting html.
Next we’ll look at a significant portion of the features available in swig by creating a series of tests.
Lastly we’ll extend swigs functionality, creating a couple of custom filters such as pluralize.
Stay tuned for the next episode, where we look at Marko a new and interesting templating language that provides some interesting features and performance characteristics.
Source for this episode is available at https://github.com/knowthen/episode-7-serving-content-in-koajs-with-swig