Jade - way to add dynamic includes

杀马特。学长 韩版系。学妹 提交于 2019-12-19 05:23:35

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/8394501/jade-way-to-add-dynamic-includes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!