Node.js 是否可以将模板的某些部分放在其他文件中?

Node.js 是否可以将模板的某些部分放在其他文件中?,node.js,pug,Node.js,Pug,我想将Jade模板的导航部分放在一个单独的文件中(navigation.Jade)-可以吗 我有layout.jade,想做如下事情: mixin ie(condition, content) | <!--[!{condition}]>!{content}<![endif]--> doctype html html head title= title meta(charset="utf-8") meta(name="viewport" c

我想将Jade模板的导航部分放在一个单独的文件中(
navigation.Jade
)-可以吗

我有layout.jade,想做如下事情:

mixin ie(condition, content)
  | <!--[!{condition}]>!{content}<![endif]-->

doctype html
html
  head
    title= title
    meta(charset="utf-8")
    meta(name="viewport" content="width=device-width, initial-scale=1.0")
    meta(name="description" content="")
    meta(name="author" content="")
    link(href="/stylesheets/bootstrap.css" rel="stylesheet")
    link(href="/stylesheets/style.css" rel="stylesheet")
    link(href="/stylesheets/responsive.css" rel="stylesheet")
    link(href="/stylesheets/layout-semiboxed.css" rel="stylesheet")
    link(href="/stylesheets/skin-red.css" rel="stylesheet")
    link(rel="shortcut icon" href="img/favicon.ico")
    +ie('if lt IE 9', '<script src="/javascripts/html5shiv.js"></script>')
    +ie('if lt IE 9', '<script src="/javascripts/respond.min.js"></script>')
    +ie('if lte IE 8', '<link href="/stylesheets/ie8.css" rel="stylesheet">')
  body(class="off")
    .wrapbox
        section.toparea
            .container
                .row
                    div(class="col-md-6 top-text pull-left animated fadeInLeft")
                    div(class="col-md-6 text-right animated fadeInRight" style="float: right;")
                        .social-icons
                            a(class="icon icon-facebook" href="#")
                            a(class="icon icon-twitter" href="#")
                            a(class="icon icon-linkedin" href="#")
                            a(class="icon icon-skype" href="#")
                            a(class="icon icon-google-plus" href="#")
        black navigation // <-- this is the part I am trying to add
        block content
extends layout

block navigation
    nav(class="navbar navbar-fixed-top wowmenu" role="navigation")
        .container
            .navbar-header
                a(class="navbar-brand logo-nav" href="index.html")
                    img(src="/images/mightywash.png" alt="logo")
                ul(id="nav" class="nav navbar-nav pull-right")
                    li(class="active")
                        a(href="/") Home
                    li
                        a(href="/locations") Locations
                    li
                        a(href="/charity") Charity
                    li
                        a(href="/washpackages") Wash Packages
                    li
                        a(href="/lubecenters") Oil Change / Lube Centers
                    li
                        a(href="/contact") Contact

如何将两者结合起来?

是的,jade有一个include指令

如果导航栏位于许多页面中,请将其放入(或包含)扩展的布局中。所以每个人都明白了。其他的只包括在几页

语法是(例如,我在每页的底部放了一个页脚)

include ../public/footer1.html
我怀疑一个“绝对路径”,例如
/public/foo.html
也可以使用-试试看(我也是新手)。你可以在这里加入.jade而不是.html更多的jade示例:()这是我的完整模板(呃,我指的是布局),可以在每页上放置页眉导航栏和页脚。YMMV:

doctype 5
html
   head
      title= title
      link(rel='stylesheet', href='/stylesheets/nextq1.css')
      block head

   body
      include ../public/header1.html

      block content

      include ../public/footer1.html

include有时可能还需要include标签。。 例如:

其中footer.jade与您当前的jade文件是同一文件夹。。。
您不能在脚本部分包含“include”

您的代码看起来很好..应该可以运行!!除非您使用的是
黑色导航
而不是
块导航

万一不行,你可以用这种方法试试

最简单的方法是使用
include

您拥有文件
navigation.jade
。要将此文件作为
layout.jade
的一部分包含在内,只需添加

include ./navigation.jade
并删除
块导航


如果使用此方法,请从
navigation.jade
文件顶部删除
extends layout
行。

包含语法是什么?请参阅编辑,但在我的示例中,它是
include../public/header1.html
include ./navigation.jade