I'm working on a Framework where developers can implement a child template in an external module. I would like to include later that template in a parent template.
Here is a basic template schema :
─ mission (parent template)
├─ succeed mission (child template)
├─ failed mission (child template)
└─ play mission (child template)
The parent template is the same for everyone. The children templates are implemented by a contributor and always displayed in a different moment (mission state).
I try two approaches in a single template file.
Implement a "block" pattern :
block mission_play
h2 Hello world!
p Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
block mission_succeed
h2 Congratulations!
p You won buddy!
block mission_failed
h2 Oh my gosh, dude, you did something realy bad
p You should try again
That one won't work because I haven't got any extend layout
directive (that I can't use because every child template is an external module). Is there any way to indicate manually to jade which template extend ?
Implement every child template in a mixin:
mixin mission_introduction(mission)
h2 Hello world!
p Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
mixin mission_succeed(mission)
h2 Congratulations!
p You win buddy!
mixin mission_failed(mission)
h2 Oh my gosh dude, you did something realy bad
p You should try again
I was going to include that template in its parent but Jade disallows usage of expressions in the include's path. That why I try to interpret the jade code directly in the parent jade template but I didn't find how. I even tried to include it with the partial
function but I can use that module without disable the default views inheritance strategy in Express.
So where I'm wrong ? What is the best strategy for that king of architecture ?
Cheers !
I finaly found a good strategy :
case mission.state
when "game"
block mission_introduction
h2 Hello world!
p Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
when "succeed"
block mission_succeed
h2 Congratulations!
p You win buddy!
when "failed"
block mission_failed
h2 Oh my gosh dude, you did something realy bad
p You should try again
Cheers !