Question

I'd like to do something like the following within a jade template.

include page-content/#{view.template}

As this won't work I have ended up with.

-if(view.path==="/")
include ../page_content/home
-else if(view.path==="/login/")
include ../page_content/login
-else if(view.path==="/join/")
include ../page_content/join
-else if(view.path==="/user/")
include ../page_content/user
 ad nauseum  

I asked TJ whether it was possible, he replied

unfortunately no, they're compile-time includes, which is somewhat necessary for a few technical reasons that I wont get into but we may eventually need to add a dynamic alternative

I'm wondering if anyone has come up with any alternatives, for example using view helpers.

I'm stuck with a big config file to generate the views - and the if-else statements in the template , I know are going to come back and haunt me. :)

If this is possible using another engine, like ejs or mustache, I'd love to know.

Any ideas much appreciated.

Was it helpful?

Solution

Feels like way too much logic in the view to me. Seems like the best way to do this would be through a dynamicHelper or possibly a mixin

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top