
Product
Introducing the Alert Details Page: A Better Way to Explore Alerts
Socket's new Alert Details page is designed to surface more context, with a clearer layout, reachability dependency chains, and structured review.
A minimal template thing for node.js web sites to use.
Works with any template engine that works with Express.
Automatically sends ETags based on the data and the template being used,
and 304 responses based on the If-None-Match request header, if the
user would be getting the same exact response as last time.
var ejs = require('ejs')
, Templar = require('templar')
, templarOptions = { engine: ejs, folder: './templates' }
// preload it. Otherwise, the first request is slow, because
// it has to load up all the templates within it.
Templar.loadFolder('./templates')
http.createServer(function (req, res) {
// note that this causes a sync fs hit the first time if
// the folder has not been loaded yet.
res.template = Templar(req, res, templarOptions)
// .. later, after figuring out which template to use ..
res.template('foo.ejs', { some: 'data', for: [ 'the', 'template'] })
//alternatively, you can add a boolean parameter to write to the response without ending it
//res.template('foo.ejs', { some: 'data', for: [ 'the', 'template'] }, false)
//just make sure you call res.end() on your own somewhere after that
}).listen(PORT)
engine: The engine to use. EJS and Jade both work.folder: The folder where template files are found.cache: Boolean. Set to false to suppress 304 responses and
re-read templates without restarting the process.Every template will be provided with a local function
include(file, data). This function will include another template via
a relative path, run it using the data provided, and return the string.
Note that this does not automatically dump the data into the calling template! It's still the caller's responsibility to actually print out the result.
If the template full.ejs contains this:
<!doctype html ALL UP IN YOUR FACE>
<html>
<head><title>yoyoyoyo</title>
<body>
<%- include("partial.ejs", { partial: 1 }) %>
<%- include("partial.ejs", { partial: 2 }) %>
<%- include("partial.ejs", { partial: 3 }) %>
<%- include("partial.ejs", { partial: 4 }) %>
<%- include("partial.ejs", { partial: 5 }) %>
</body></html>
Then, in the same folder, you had a partial.ejs that contained:
<p>is for <%= partial %>
then the resulting output would be:
<!doctype html ALL UP IN YOUR FACE>
<html>
<head><title>yoyoyoyo</title>
<body>
<p>is for 1
<p>is for 2
<p>is for 3
<p>is for 4
<p>is for 5
</body></html>
Note that full.ejs actually prints out the result of the include call.
FAQs
A lightweight template thing
The npm package templar receives a total of 13 weekly downloads. As such, templar popularity was classified as not popular.
We found that templar demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.

Product
Socket's new Alert Details page is designed to surface more context, with a clearer layout, reachability dependency chains, and structured review.

Product
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.

Research
Malicious PyPI package sympy-dev targets SymPy users, a Python symbolic math library with 85 million monthly downloads.