11

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.

Chin
  • 12,582
  • 38
  • 102
  • 152

1 Answers1

2

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

Paul
  • 35,689
  • 11
  • 93
  • 122
  • Yep, that's the problem. I have a config file with the view template names and routes. I'm trying to generate the view's content area based on the config. thus keeping the template DRY. So when the request is made - depending on the route the content area of the template needs to change. I'm forced to use the config, and am wondering if I can actually do it in Jade as all is compiled on app start. – Chin Dec 06 '11 at 05:36
  • I suppose using a dynamicHelper, I can render content then pass it into the view. thanks – Chin Dec 06 '11 at 05:43