【问题标题】:how to load filename to include from defined variable如何从定义的变量中加载要包含的文件名
【发布时间】:2015-09-23 18:47:07
【问题描述】:

我有一个变量,它定义了要包含的模板名称:

- var content = 'content-css.jade'

然后我想使用这个变量值来定义应该包含哪个文件:

include #{content}

但jade会按原样解释它,因此它会查找名为#{content}而不是content-css.jade的文件。

这是完整的代码:

include ./partials/head.jade

- var content = 'content-css.jade'
body
  .fw-layout
    .fw-topbar.sticky topbar
    .fw-middle
      .fw-sides
        .fw-sideleft
          .fw-inner.sticky
        .fw-content
          .fw-inner
            .fw-page
              include ./partials/grid-page.jade

那么grid-page.jade就有了自己的html结构

... grid-page static header ...

... grid-page dynamic content ...
include #{content}

... grid-page static footer ...

【问题讨论】:

    标签: templates variables pug


    【解决方案1】:

    好的,我找到了答案,因为 Jade 不支持包含变量,所以我使用了 mixin:

    mixin content
      include ./partials/content-css.jade
    

    然后包含

    +content
    

    【讨论】:

      猜你喜欢
      • 2019-12-17
      • 1970-01-01
      • 2011-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-25
      • 2014-02-01
      相关资源
      最近更新 更多