如何在 expressjs 中调用多个文件 .pug?
How to Call Multiple File .pug in expressjs?
我想调用几个.pug 文件以便它动态运行。但是我得到一个错误。
res.render('layout');
res.render('body');
res.render('footer');
有谁知道如何克服这个问题?我无法调用多个 .pug 文件
你使用你的哈巴狗文件调用它(不是你的路由文件,而是你的哈巴狗文件)
header.pug
nav.nav-top
ul
li.menu-item
a(href='/').menu Home
a(href='/dashboard').menu Dashboard
a(href='/dashboard/thelist').menu thelist
a(href='/login').menu Login
footer.pug
main.pug [布局文件]。注意包含部分(例如包含../part/header-top)。我的零件文件夹与布局文件夹不同。它只是意味着包含 pug 文件,它将获取其他 pug 文件的内容。只需放入 include pugfilename.
doctype html
html
head
title #{title} 23
link(rel='stylesheet' href='/css/style.css')
//- script(src='/js/main.js')
//- script(src="https://code.jquery.com/jquery-3.1.0.min.js")
body
container.page
include ../part/header-top
include ../part/header-main
h1 Hello main.pug
block content
br
hr
block kicker
footer
p Copyright © 2019
script(src='/js/main.js')
在您的视图中,从您的路线呈现的 pug 文件。请注意您的 pug 文件布局文件的扩展和文件位置。我把我的布局文件叫做main,所以指向它上你的side.Block内容就是页面的内容。它会将块内容放入您的布局页面,其中显示块内容。
extends ../../template/layout/main
block content
h1 View
a(href="/dashboard/thelist") The List
注意:根据您的布局和文件夹结构,您的会与我的不同!
如果您需要更多帮助,您需要详细说明您的文件夹结构!
如果您需要更多帮助,这是我的设置示例(它是关于 mixin,但它处理您调用 pug 文件的问题):Include pug mixin from other view folder
我想调用几个.pug 文件以便它动态运行。但是我得到一个错误。
res.render('layout');
res.render('body');
res.render('footer');
有谁知道如何克服这个问题?我无法调用多个 .pug 文件
你使用你的哈巴狗文件调用它(不是你的路由文件,而是你的哈巴狗文件)
header.pug
nav.nav-top
ul
li.menu-item
a(href='/').menu Home
a(href='/dashboard').menu Dashboard
a(href='/dashboard/thelist').menu thelist
a(href='/login').menu Login
footer.pug
main.pug [布局文件]。注意包含部分(例如包含../part/header-top)。我的零件文件夹与布局文件夹不同。它只是意味着包含 pug 文件,它将获取其他 pug 文件的内容。只需放入 include pugfilename.
doctype html
html
head
title #{title} 23
link(rel='stylesheet' href='/css/style.css')
//- script(src='/js/main.js')
//- script(src="https://code.jquery.com/jquery-3.1.0.min.js")
body
container.page
include ../part/header-top
include ../part/header-main
h1 Hello main.pug
block content
br
hr
block kicker
footer
p Copyright © 2019
script(src='/js/main.js')
在您的视图中,从您的路线呈现的 pug 文件。请注意您的 pug 文件布局文件的扩展和文件位置。我把我的布局文件叫做main,所以指向它上你的side.Block内容就是页面的内容。它会将块内容放入您的布局页面,其中显示块内容。
extends ../../template/layout/main
block content
h1 View
a(href="/dashboard/thelist") The List
注意:根据您的布局和文件夹结构,您的会与我的不同!
如果您需要更多帮助,您需要详细说明您的文件夹结构!
如果您需要更多帮助,这是我的设置示例(它是关于 mixin,但它处理您调用 pug 文件的问题):Include pug mixin from other view folder