So I'm trying to use consolidate.js to render swig templates with express, but I get the following error when I try to "extend" one template from another:
Error: ENOENT, no such file or directory '//one.html
In my app.js
file I setup swig as my rendering engine (only including relevant code):
var consolidate = require('consolidate');
app.set('view engine', 'html');
app.set('views', __dirname + '/views');
app.engine('.html', consolidate.swig);
app.get('/test', function(req, res) {
res.render('two');
});
And I have a base template, one.html
:
<h3>My Site</h3>
{% block content %}
Welcome
{% endblock %}
Then an inheriting template, two.html
:
{% extends 'one.html' %}
{% block content %}
This is an inner page.
{% endblock %}
So why does swig look for one.html
with a path of //one.html
(like in the error above?) Thanks for any help.
Figured it out after looking at the swig documentation (specifically the section on usage with Express.) All I had to do was initialize swig, and tell it where to look for "extended" templates:
var consolidate = require('consolidate'),
swig = require('swig');
app.set('view engine', 'html');
app.set('views', __dirname + '/views');
app.engine('.html', consolidate.swig);
app.get('/test', function(req, res) {
res.render('two');
});
/* Tell swig where to look for templates when one extends another. */
swig.init({ root: __dirname + '/views' });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With