如何将参数传递给 pug 中的另一个文件?
我有一个layout.pug
文件,该文件设置了我项目中所有页面的布局。
doctype html
html(lang='en')
include head.pug
body(class='')
include header.pug
block content
include footer.pug
和home.pug
这样的文件,
extends layout.pug
block content
p some content in here
问题是我想在我的项目中的每个页面中为< body>
标记设置一个单独的类名称。
例如:home.pug
具有< hody class =“ page-home”>
。和keyword.pug
具有< body class =“ pag-keyword”>
我尝试通过put body(class ='#{class ='#{ BodyClass}')
在layout.pug
中
doctype html
html(lang='en')
include head.pug
body(class='#{bodyClass}')
include header.pug
block content
include footer.pug
,并声明变量- 让BodyClass ='Page-Home'但这不起作用,
extends layout.pug
- let bodyClass = 'page-home';
block content
p some content in here
任何人都知道如何修复,请帮助我。谢谢 !!!
I have a layout.pug
file that setup a layout for all page in my project.
doctype html
html(lang='en')
include head.pug
body(class='')
include header.pug
block content
include footer.pug
And home.pug
file like this
extends layout.pug
block content
p some content in here
The problem is I want to set a separate class name in <body>
tag for every page in my project.
Eg: home.pug
have <body class="page-home">
. And keyword.pug
have <body class="page-keyword">
I've tried to use interpolation by put body(class='#{bodyClass}')
in layout.pug
doctype html
html(lang='en')
include head.pug
body(class='#{bodyClass}')
include header.pug
block content
include footer.pug
and declare a variable - let bodyClass = 'page-home'
in home.pug
but it not work
extends layout.pug
- let bodyClass = 'page-home';
block content
p some content in here
Anyone know how to fix please help me. Thanks !!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

在顶部的
layout.pug
文件中添加块变量
,并在home.pug
文件中的extendslayout.pug< /code> 将
块变量
添加到您的变量中。布局中的
块变量
将被home.pug
中的块变量
替换。如果您想向块添加一些变量,您应该在
home.pug
中使用append Variables
。布局.pug
home.pug
In the
layout.pug
file at top add theblock variables
and in thehome.pug
file, afterextends layout.pug
add theblock variables
with your variable.The
block variables
in layout will be replaced wich yourblock variables
in thehome.pug
.If you want add some variables to the block, you should use
append variables
in thehome.pug
.layout.pug
home.pug