玉 - 添加动态的方式包括 [英] Jade - way to add dynamic includes

查看:100
本文介绍了玉 - 添加动态的方式包括的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  include page-content /#{view .template} 

由于这不行,我已经结束了。

  -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

我问TJ是否有可能,他回答说


不幸的是,他们是编译时的包括,这是有点必要的一些技术原因,我不会进入,但我们可能最终需要添加一个动态的替代方案

我想知道是否有人提出了任何替代方案,例如使用视图助手。



我被卡住了双g配置文件生成视图 - 和模板中的if-else语句,我知道会回来,困扰我。 :)



如果可以使用其他引擎,如ejs或胡子,我很想知道。



任何想法都非常感激。

解决方案

在我看来,感觉像是太多的逻辑。似乎最好的方法是通过 dynamicHelper 或者可能一个mixin


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.

解决方案

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

这篇关于玉 - 添加动态的方式包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆