pug-layout
A module that gives you the possibility of loading a layout in variable
Install
npm install pug-layout
Usage
layout.pug:
div(foo="bar") block content
index.pug:
block content span= text
app.js:
var pl = ; var layout = 'layout.pug'; layout;
And you will get this index.html:
this is the content
Load Mixin
You can load a file as a mixin, that means the content of the file can be used as mixin:
.includeMixin(filePath,mixinArgs,mixinName)
:
- mixinArgs: string containing arguments of the mixin, if multiple separate them with comma
,
- mixinName: the name of mixin (optional), if not provided the mixin will be named with its filename.
Ex:
pet.pug:
p div= type div= age
index.pug:
block content span= text +pet('dog',5)
app.js:
var pl = ; var layout = 'layout.pug'; layout; layout;
And now you will get index.html:
this is the content dog 5
Include at Top
You can include a file at top of layout. Useful when you want to include multiple mixins from one file.
.includeAtTop(filePath)
:
Ex:
head.pug:
section.head I'm the header
app.js:
var pl = ; var layout = 'layout.pug'; layout;layout; layout;
And now you will get index.html:
I'm the headerthis is the content dog 5
Get HTML
You can get the rendered HTML without writing it in a file, using convert(filePath)
instead of convertInFile(filePath,dist)
.
Ex:
var html = layout;
Page Class
You can use page classes too:
var page = 'index.pug';
And extend it programatically:
page;
Or extend it from a file path:
page;
Get the HTML:
var html = page;
Or render directly into a file:
page;
render Page with Layout
Instead of using 'convert' and file path you can use a Page instance with Layouts:
var html = layout;
Or render directly into a file:
layout;