I would like to make my Jade page extend different layouts, depending on a condition. So my code looks like this:
if myConditionVariable
extends layout1
else
extends layout2
block content
p here goes my content!
Now this does not work. It seems as if only the last defined extends will be respected, regardless of the conditions. I also tried dynamically defining the templatename, such as
extends myLayoutNameVariable
and set the myLayoutNameVariable in different manners (express dynamic helper function, set it as var, local var etc...)
Is there any other solution for conditional layouts or can someone tell me what i am doing wrong?
Cheers, simon
Can you do something like:
?
If not, do you pass
myConditionVariable
correct when you tell to render that view? A short example for this:This seems to be an issue that's still open on github.
So, a slightly less intrusive way to deal with this is to change the layout itself.
I added a bit of middleware, and the rest flows..
Now that this is set, "isAjax" is available to jade.
In my "layout.jade" (the template you will extend from), I do this:
I have stripped out the other elements of the full layout.jade for (hopefully) clarity.
Finally, my normal views that extend layout.jade work without modification (this jade template includes both cases).
I hope it's not too late but i ran across this issue and I think I figured out a workaround:
Make a layout.jade that conditionaly includes both layouts:
In your view, extend
layout.jade
, and defineconditionalVariable
in the controller (true
/false
):Disco!