Squirrelly
Get StartedTemplate SyntaxAPICommunity
7.x.x
7.x.x
  • Overview
  • FAQ
  • Demo
  • Performance
  • Changelog
  • Getting Started
    • Installation
    • Your First Template
    • Why Squirrelly?
    • What's a template engine?
  • Template Syntax
    • The Basics
    • Global References
    • Helper References
    • Filters
    • Helpers
    • Self-Closing Helpers
    • Native Helpers
    • Setting custom tags
    • Partials
    • Built-in Helpers
  • API
    • API Overview
    • Compile
    • Render
    • renderFile
    • load
    • defineFilter
    • setDefaultFilters
    • autoEscaping
    • defineHelper
    • defineNativeHelper
    • definePartial
    • defaultTags
  • Recipes
    • Squirrelly with ExpressJS
  • Guides
    • Generating Badges with Squirrelly
Powered by GitBook
On this page
  1. Recipes

Squirrelly with ExpressJS

Since Squirrelly exports the __express helper, it works out-of-the-box with Express.

Though Squirrelly handles caching, it isn't very sophisticated and the cache only lives for the life of the program (it's stored in a variable). You may want to implement your own caching solution.

index.js
let express = require('express');
let path = require('path');
let app = express();

app.set('view engine', 'squirrelly')

app.get('/', function (req, res) {
    res.render('index', {
        name: 'Title',
        fav: 'Squirrelly'
    })
})

let server = app.listen(4000, function () { // This starts the server
    console.log("listening to request on port 4000");
});
views/index.squirrelly
<!DOCTYPE html>
<html>
<head>
    <title>{{name}}</title>
</head>
<body>
<p>My favorite template engine is {{fav}}</p>
</body>
</html>

PreviousdefaultTagsNextGenerating Badges with Squirrelly

Last updated 5 years ago