fastify-squirrelly
Plugin for rendering Squirrelly Templates
Requirements
node >= 6
fastify >= 2.0
Install
npm install fastify-squirrelly
Usage
const fastify = ; fastify; fastify; fastify;
Options
decorator
- change the decorator name. defaultsqrly
autoEscape
- set autoEscaping on squirrelly. defaultfalse
charset
- default utf-8templates
- directory templates are read from. default (__dirname, "/templates")partials
- directory partials are read from. default (__dirname, "/partials")helpers
- directory helpers are read from. default (__dirname, "/helpers")filters
- directory filters are read from. default (__dirname, "/filters")nativeHelpers
- directory nativeHelpers are read from. default (__dirname, "/nativeHelpers")debug
- Allows you to see the template data as json. defaultfalse
Examples
Hello World Example
This example covers creating a squirrelly template that renders Hello World!
and serving it from a fastify server. The completed example can be found in examples/hello-world
Install fastify and fastify-squirrelly
npm install fastify fastify-squirrelly
Create the Fastify server
// server.jsconst fastify = logger: true; fastify; fastify; fastify;
Create the Squirrelly template file
create a folder called templates in the same directory as the server file. Then create a file named hello.html in that folder.
.
+-- server.js
+-- templates
| +-- hello.html
<!-- hello.html -->Hello, {{name}}!
start the server!
node server.js
Open a browser and go to localhost:3000 and you should see Hello, World!
.
Congrats! you just rendered your first template using fastify-squirrelly.
Try passing a value other than 'World'
and restart the server.