New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

backticks

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backticks

Express engine creator for the basic use of ES6 template literals (backticks) for templating

  • 0.1.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
Maintainers
1
Weekly downloads
 
Created
Source

Backticks

An Express view engine for using ES2015 Template Literals.

Installation

$ npm i backticks

Features

  • Compiled and interpreted by V8 (minimun overhead to the project)
  • Learning new syntax is not required
  • Automatic escaping of locals
  • Support for layout using generator functions
  • Niceties like automatic array joining

Usage

Basic Usage

The basics required to integrate backticks renderer are:

var express = require('express'),
  backticks = require('backticks'),
  app = express();
  
app.engine('html', backticks());
app.set('views', 'views');
app.set('view engine', 'html');

app.get('/', function(req, res) {
  res.render('index', {title: 'Welcome', message: "Hello World"});
});

app.listen(3000);

Before Express can render template files, the following application settings must be set:

  • views, the directory where the template files are located. Eg: app.set('views', './views')
  • view engine, the template engine to use. Eg: app.set('view engine', 'html')

HTML template file named index.html in the views directory is needed, with the following content:

<!DOCTYPE html>
<html>
<head>
    <title>${title}</title>
</head>
<body>
    <h1>${message}</h1>
</body>
</html>

Using a Layout file

Backticks supports the usage of a layout fil: it does so by combining the view with the configured layout. The layout is processed in a generator function, so you have access to yield Within it (identifies where the contents of the view currently being rendered is inserted).

Example:

var express = require('express'),
  backticks = require('backticks'),
  app = express();

app.engine('html', backticks({
  caching: true,
  layoutFile: join(__dirname, './views/layout.html')
}));
app.set('views', 'views');
app.set('view engine', 'html');


app.get('/', function(req, res) {
  res.render('index', {message: "Hello World"});
});

app.listen(3000);

Layout File:

<html>
  <head>
    <title>Hey, up here!</title>
  </head>
  <body>
    <div id="page">
      ${yield}
    </div>
  </body>
</html>

Template:

<div>
  <h1>${message}</h1>
</div>

Should I use this in production code?

Use Backticks if you need something quick and simple. It is not as readable as the template syntax supported by Handlebars.js and similar templating engines. On the other hand, it is lightweight and new syntax is introduced: It's just JavaScript.

Keywords

FAQs

Package last updated on 03 Jan 2018

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc