
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
npm install templatex
or
npm install --save templatex
var templateX = require('templatex'),
template = "{{message}}, {{name}}",
obj = {message: "Hello", name: "Johnny"};
templateX.render(template, obj) // result: "Hello, Johnny"
From version 1.2.0, you can use templateX as Express template engine using express method.
hello.html file in /views folder:
<h1>Hello, {{name}}</h1>
APP js file:
var express = require('express');
app = express(),
templatex = require('templatex');
app.engine('html', templatex.express);
app.set('view engine', 'html');
app.set('views', __dirname + '/views');
app.get('/', function(req, res) {
res.render('hello', {name: 'World'});
});
app.use(function (req, res) {
res.sendStatus(404);
});
var server = app.listen(8000);
{name: 'Simon',
details: [
job: 'programmer',
hobby: 'country <b>music</b>'
],
favalbums: [
{name: "American Recordings", author: "Johnny Cash"},
{name: "Train A-Comin’", author: "Steve Earle"},
]
}
{{property}} and {{&property}}
<p>My name is {{name}}, and I love {{details.hobby}}!</p>
<p>My name is {{name}}, and I love {{&details.hobby}}!</p>
\\result of first: "<p>My name is Simon, and I love country <b>music </b>!</p>"
\\result of '&' tag: "<p>My name is Simon, and I love country <b>music</b>!</p>"
{{#property}}content{/property}} and {{%property}}content{{/property}}
as "true" statement
{{#details.job}}We have information about {{name}} job{{/details.job}}{{#details.family}} and family{{/details.family}}!!
{{%details.job}}We have information about {{name}} job{{/details.job}}{{%details.family}} and family{{/details.family}}!!
\\BOTH result "We have information about Simon job!!"
as loop we can only use '#' tag
<ul>
{{#favalbums}}<li>{{name}} by {{author}}</li>{{/favalbums}}
</ul>
<ul>
{{%favalbums}}<li>{{name}} by {{author}}</li>{{/favalbums}}
</ul>
\\result #
<ul>
<li>American Recordings by Johnny Cash</li>
<li>Train A-Comin’ by Steve Earle</li>
</ul>
\\result %
<ul>
<li>Simon by</li>
</ul>
{{^property}}content{/property}}
as "true" statement
{{^details.family}}We don`t have information about {{name}} family{{/details.family}}{{^details.job}} and job{{/details.job}}!!
\\result "We don`t have information about Simon family!!"
{%{ text }}
{%{My name is {{name}}!}}
//result "{{My name is Simon!}}"
{{.*property}}
When looping...
<ul>
{{#favalbums}}<li>I am {{.name}} and I love {{name}} by {{author}}</li>{{/favalbums}}
</ul>
\\result
<ul>
<li>I am Simon and I love American Recordings by Johnny Cash</li>
<li>I am Simon and I love Train A-Comin’ by Steve Earle</li>
</ul>
FAQs
Easy templates with JavaScript
We found that templatex 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 Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.