【问题标题】:How to Call Multiple File .pug in expressjs?如何在 expressjs 中调用多个文件 .pug?
【发布时间】:2019-09-28 22:26:19
【问题描述】:

我想调用几个 .pug 文件以便它动态运行。但我得到一个错误。

res.render('layout');
res.render('body');
res.render('footer');

有谁知道如何克服这个问题?我无法调用多个 .pug 文件

【问题讨论】:

    标签: javascript express pug


    【解决方案1】:

    你使用你的 pug 文件来调用它(不是你的路由文件,而是你的 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
    

    页脚.pug

    main.pug [布局文件]。注意包含部分(例如包含 ../part/header-top)。我的零件文件夹与我的布局文件夹不同。它只是意味着包含 pug 文件,它将获取其他 pug 文件的内容。只需输入包含 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 文件布局文件的扩展和文件位置。我把我的布局文件称为main,所以在你这边指向它。块内容是页面的内容。它会将块内容放入您的布局页面中,其中显示块内容。

    extends ../../template/layout/main
    
    block content
        h1 View
        a(href="/dashboard/thelist") The List
    

    注意:根据您的布局和文件夹结构,您的会与我的不同!

    如果您需要更多帮助,您需要提供您的文件夹结构的详细信息!

    如果您需要更多帮助,这是我的设置示例(它关于 mixin,但它处理您调用 pug 文件的问题):Include pug mixin from other view folder

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-16
      • 2021-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-06
      • 1970-01-01
      相关资源
      最近更新 更多