I understand that Pug does not support dynamic includes or extends in templates. Ie
extend path/to/template
works but not
ex
There is no way to do this for now, but you can work out your application architecture without dynamic extends.
Make a layout.jade that conditionally include multiple layouts:
layout.jade:
if conditionalVariable
include firstLayout.jade
else
include otherLayout
In your view, extend layout.jade
, and define conditionalVariable
in the controller (true
/false
):
view.jade:
extends layout
block content
p here goes my content!
Pass configurations to the layout
- var lang = req.getLocale();
doctype html
block modifyLayout
split the project into multiple entrances, each entrance extends the layout and passes its different configs, and includes different things in different blocks
extends ../layout
block modifyLayout
- var lang = "en" //force language to be en in this page.
block body
include my-page-body
use something like terraform which uses pug as its rendering engine, but it enables you to use dynamic partials like this
!= partial(dynamicFileFromVariable)