Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tattali/electron-twig
Electron module to render Twig templates
https://github.com/tattali/electron-twig
Last synced: 11 days ago
JSON representation
Electron module to render Twig templates
- Host: GitHub
- URL: https://github.com/tattali/electron-twig
- Owner: tattali
- License: mit
- Created: 2017-08-11T15:21:28.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-08T10:11:01.000Z (over 5 years ago)
- Last Synced: 2024-11-24T17:36:06.408Z (29 days ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/electron-twig
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Electron Twig
[![npm](https://img.shields.io/npm/v/electron-twig.svg)](https://www.npmjs.com/package/electron-twig)
[![npm](https://img.shields.io/npm/dt/electron-twig.svg)](https://www.npmjs.com/package/electron-twig)
[![David](https://img.shields.io/david/tattali/electron-twig.svg)](https://www.npmjs.com/package/electron-twig)Get [Twig.js](https://github.com/twigjs/twig.js) the JS implementation of the Twig Templating Language on [electron](https://github.com/atom/electron) projects.
This package is a simple `file protocol interceptor` which compiles files with `.twig` extension.
## Installation
```
npm install electron-twig
```## Usage
```js
const {app, BrowserWindow} = require('electron')
const twig = require('electron-twig')app.on('ready', () => {
let win = new BrowserWindow({width: 800, height: 600})win.loadURL(`file://${__dirname}/views/index.html.twig`)
// etc.
})
```Put variables in template
```js
const {app, BrowserWindow} = require('electron')
const twig = require('electron-twig')app.on('ready', () => {
let win = new BrowserWindow({width: 800, height: 600})win.loadURL(`file://${__dirname}/views/index.html.twig`)
twig.view = {
foo: 'bar'
}// etc.
})
```If you have an error like that :
```
you are using twig.js in sync mode in combination with async extensions
```You have to use the async version.
For async version add a variable `is_async: true`
```js
const {app, BrowserWindow} = require('electron')
const twig = require('electron-twig')app.on('ready', () => {
let win = new BrowserWindow({width: 800, height: 600})new Promise(function(resolve, reject) {
setTimeout(function() {
resolve();
}, 300);
}).then(() => {win.loadURL(`file://${__dirname}/views/index.html.twig`)
twig.view = {
foo: 'bar',
is_async: true
}});
// etc.
})
```