Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cassiozen/backticks
An Express view engine for using ES2015 Template Literals.
https://github.com/cassiozen/backticks
template-engine
Last synced: about 2 months ago
JSON representation
An Express view engine for using ES2015 Template Literals.
- Host: GitHub
- URL: https://github.com/cassiozen/backticks
- Owner: cassiozen
- Created: 2017-10-19T16:10:58.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-03T11:23:31.000Z (almost 7 years ago)
- Last Synced: 2024-11-02T17:07:35.257Z (about 2 months ago)
- Topics: template-engine
- Language: JavaScript
- Homepage:
- Size: 75.2 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Backticks
An Express view engine for using ES2015 Template Literals.
## Installation
```bash
$ npm i backticks
```## Features
* Learning new syntax is not required
* Niceties like automatic escaping & automatic array joining
* Layout as a generator function## Usage
### Basic Usage
The basics required to integrate backticks renderer are:
```javascript
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:
```html
${title}
${message}
```
### Using a Layout file
Backticks supports the usage of a layout file. The layout is processed in a generator function, so you have access to `yield` Within it.
By default, Backticks will try to load a "layout" file using the same folder and extension of your views.
Example:
```javascript
var express = require('express'),
backticks = require('backticks'),
app = express();app.engine('html', backticks({
caching: true
}));
app.set('views', 'views');
app.set('view engine', 'html');app.get('/', function(req, res) {
res.render('index', {message: "Hello World"});
});app.listen(3000);
```**`views/layout.html`:**
```html
Hey, up here!
${yield}
```
**Template:**
```html
${message}
```## Settings
These are the available options when instantiating backticks:
| Option | Description | Default Value
|---|---|---|
| caching | Wheter or not Backticks should cache views | false |
| layoutFile | File to use as layout for views | [views folder]/layout.[view engine]
| fnWhitelist | By default, values returned from functions provided in locals are automatically escaped. You can whitelist functions to avoid auto escaping | [Array.prototype]## 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.