Given a sample structure:
/layout.jade
/really/deep/dir/inside/my/template/folder/example.jade
Is there any way I can extend layout.jade in example.jade without having to keep track of the number of parent directories?
This works as intended tho:
extends ../../../..etc../../../layout
But it would be preferable to do something like:
extends /layout
Or even alias/hardlink and use it like:
extends layout
Also assuming somebody knows a solution, can it also be applied to include?
Jade is a template engine for node. js and the default rendering engine for the Express web framework. It is a new, simplified language that compiles into HTML and is extremely useful for web developers.
In order to use Jade with Express. js, create sample. jade file inside views folder and write following Jade template in it. doctype html html head title Jade Page body h1 This page is produced by Jade engine p some paragraph here..
All jade files need to be transformed in the HTML. Also don't forget that you need to install other dependencie like express, nodemailer, etc (see requires in the source code). And the application should by available on http://localhost/3000. All Jade templates will be correctly rendered and displayed as HTML.
There is a change that was introduced in this particular commit.
Basically, if the first character found in the include statement is a forward slash and basedir is defined, it will look for the template in that path.
You must first setup Jade:
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.locals.basedir = app.get('views');
Then, from any template, no matter how deeply nested, you can do:
include /layout
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