Parag is a nodejs templating engine inspired by the beautiful syntax of laravel blade.
npm install parag
Below is an example of how to use parag
const Parag = require('parag');
const data = {
title: 'The matrix',
year: '1999',
};
const result = Parag.render('<p>{{title}} was released in {{year}}</p>', data);
console.log(result); // => <p>The matrix was released in 1999</p>Same code with typescript
import * as Parag from 'parag';
const data: Record<string, string> = {
title: 'The matrix',
year: '1999',
};
const result: string = Parag.render('<p>{{title}} was released in {{year}}</p>', data);
console.log(result); // => <p>The matrix was released in 1999</p>const express = require('express');
const app = express();
const port = 3000;
app.set('views', './view');
app.set('view engine', 'parag');
app.get('/', (req, res) => {
res.render('hello', { name: 'void' });
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});- Go to Code > Preferences > Settings
- Search "File associations"
- Click on "Add Item"
- Add (
*.parag) as extension(item) andhtmlas associated language(value).
All results are escaped by default.
<p>Hello {{name}}</p>If it's javascript, parag will interpolate the result.
<div>
<p>{{["rice", "beans"].join(",")}}</p>
<p>{{new Date()}}</p>
</div>You can also render unescaped results
<div>{{! article.body !}}</div>Simple if statement
@if(user)
<p>{{user.name}}</p>
<p>@endif</p>if, else if and else chain.
@if(user.age > 21)
<p>Proper adult</p>
@elseif(user.age > 18 && user.age < 21)
<p>Early adult</p>
@else
<p>Kid</p>
@endifTo keep things simple, parag only supports javascript for loop statements
- For..of loop statement
<ul>
@for(let user of users)
<li>{{user.name}}</li>
@endfor
</ul>- For...in loop statement
<ul>
@for(let prop in user)
<li>{{user[prop]}}</li>
@endfor
</ul>- for loop statement
<ul>
@for(let i = 0; i < 5; i++)
<li>{{ "count: " + i }}</li>
@endfor
</ul>This project is licensed under the MIT license. See the LICENSE file for more info.