在帕格/翡翠dynamic包括解决方法

据我所知,帕格不支持在模板中dynamic包含或扩展。 即

extend path/to/template 

工作但不是

 extend #{dynamic_path_to_template} 

有没有一个解决方法(无论是复杂的),将允许相同的目标,在运行时修改视图使用的模板

上下文 :我的用例是我正在开发一个npm模块,用于扩展其他视图的模板位于模块内部。 在模块发布和安装之后,path将被定义(即node_modules / my_module / path / to / template),但是在开发阶段,我只需要能够“npm link”到模块并拥有模板工作。 我也不想硬编码的链接,所以我可以发布相同的代码作为testing。

目前没有办法做到这一点,但是你可以在没有dynamic扩展的情况下制定你的应用程序架构。

可能的解决scheme#1

  1. 制作一个有条件地包含多个布局的layout.jade:

     layout.jade: if conditionalVariable include firstLayout.jade else include otherLayout 
  2. 在你看来,扩展layout.jade ,并在控制器中定义conditionalVariabletrue / false ):

     view.jade: extends layout block content p here goes my content! 

可能的解决scheme#2

  1. 将configuration传递给布局

     - var lang = req.getLocale(); doctype html block modifyLayout 
  2. 将项目分成多个入口,每个入口扩展布局并传递不同的configuration,并在不同的块中包含不同的东西

     extends ../layout block modifyLayout - var lang = "en" //force language to be en in this page. block body include my-page-body 

可能的解决scheme#3

使用类似terraform的东西,它使用帕格作为其渲染引擎,但它使您可以使用像这样的dynamic分部

 != partial(dynamicFileFromVariable)