
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
squirrelly
Advanced tools
A simple yet powerful modern template engine that works with ExpressJS and as a standalone module.
Squirrelly is a modern template engine supporting ExpressJS, in-browser functions, and even use as a standalone Node.JS module!
Note: right now only basic option pass-ins are supported but all of the features described below are expected to be rolled out in the coming months.
Usage -- Install With NPM -- Use with ExpressJS -- Use with Node.js Syntax -- Basic values -- If statements -- For loops -- While loops -- Includes/Partials -- Helper functions
Squirrelly can be used in the browser, as NodeJS, and even as an ExpressJS plugin!
npm install -g squirrelly
Download squirrelly
(npm install squirrelly --save
)
Create an index.sqrl
file (that's explained below, but basically you just put options between double brackets)
Create your JS file. An example is shown below
const express = require('express')//Require express
const app = express()
app.set('views', 'tests/views') //specify views directory (where your sqrl files are)
app.engine('sqrl', require('squirrelly').__express);//Set the template engine to squirrelly, and make it use .sqrl files. If you don't do this, you'll have to use the file extension .squirrelly
app.set('view engine', 'sqrl'); (use squirrelly as a template engine)
app.get('/', function (req, res) {//When a request is made to the server
res.render('index', { title: 'Hey', message: 'Hello there!', birthday: 'today', truth: true, untruth: false})//Render index.sqrl, with options
})
app.listen(3000, function () {//Start the server
console.log('Should be rendering on port 3000...')
})
var sqrl = require('squirrelly')
sqrl.returnHTML('your string with squirrelly stuff')
All variables are passed in through an options object that looks like this: {foo: 1, bar: "hi", etc: {spanish: "hola", hi: "howdy", andso: "on"}}
Put variable inside double brackets, like so: I said {{ bar }}
. Having a space after the closing brackets and before the ending brackets is optional, and single vs. double quotes is too. You may pass in objects like:
I said {{ etc }}
(returns stringified object etc
)etc[(the value of the object 'bar'
I said {{ etc["hi"] }}
returns "howdy"I said {{ etc[bar] }}
returns "howdy"I said {{ etc['spanish'] }}
(returns "hola")etc['spanish'
or etc['spanish']['spanishobjectchild']
. You cannot use notation like etc.spanish
or etc["spanish"["child"]]
The basic syntax of an if
statement looks like:
{if(some condition){
display this
and this etc}}
undefined
or null
: {if(somevalue){display this}}
undefined
or null
: {if(!somevalue){display this}}
{if(somevalue === "hi"){display this}}
-- You can substitute ===
for >==
, >==
, !==
, or type
(checks value type, returns string
, etc). Comparators like ==
or !=
are not supported.
-- Please note that you can't include more advanced expressions like {if(somevalue + othervalue === 4){display this}}
.The basic syntax of an for
loop looks like:
{for(somevar in somearrayorobject){
display this
and this etc}}
And renders the inner content each time it's called.
{for(post in posts){<h2>{{post.title}}</h2><p>{{post.description}}</p>}}
{for(n < 10){The current number is {{n}}}}
The basic syntax of a while
loop looks like:
{while(somevar === somevalue){
display this
and this etc}}
And renders the inner content each time it's called.
{while(apples <== 87){display this and this etc}}
The basic syntax of an include
looks like:
{include(somefile){optionsforthatfile}}
It includes a specific file and optionally parses it with a specific set of options.
{include(sidebar.html.sqrl){}}
A helper function is a 3rd-party function that accepts content and (optionally) options and returns parsed content.
The basic syntax of a helper
looks like:
{helper(functionname, options){content}}
{helper(googlemaps, {globaloptions: options, latitude: "144", longitude: "23"){}}
FAQs
Lightweight, fast, and powerful JS template engine. Supports helpers, filters, template inheritance
The npm package squirrelly receives a total of 14,674 weekly downloads. As such, squirrelly popularity was classified as popular.
We found that squirrelly demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.