Socket
Book a DemoInstallSign in
Socket

templatex

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

templatex

Easy templates with JavaScript

latest
Source
npmnpm
Version
1.2.2
Version published
Maintainers
1
Created
Source

templateX - node.js module

Easy templates with JavaScript

Latest Stable Version License NPM Downloads

Getting started

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"

templateX with Express >= 1.2.0

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);

Tags:

{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 &lt;b&gt;music &lt;/b&gt;!</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>

Keywords

template

FAQs

Package last updated on 22 Oct 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.