Pug.js - 传递pug文件以使用JS

问题描述 投票:0回答:1

我有一个Main.pug文件,我正在使用它作为我希望包含在其中的多个其他.pug文件的容器。然而,其他文件集不是静态的,即Main.pug可能包括A.pug或它可能包括B.pug。使用哪个文件将从快递传递类似于以下内容:

app.get('/', function(req, res) {
    res.render('main', {section:"A.pug"}) 
})

我在Main.pug中尝试了几种方法,包括以下内容:

include #{section}

它似乎不起作用。有没有人有关于如何实现这一目标的建议或提示?

javascript templates pug
1个回答
0
投票

试试这个。

app.get('/', function(req, res) {
    res.render('main', {section:"A"}) 
})

main.pug

-if (section == 'A')
    include A.pug
-else if(section == 'B')
    include B.pug

希望能帮助到你。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.