如何将参数传递给 pug 中的另一个文件?

发布于 01-21 02:46 字数 1072 浏览 3 评论 0原文

我有一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我是男神闪亮亮2025-01-28 02:46:24

在顶部的 layout.pug 文件中添加块变量,并在 home.pug 文件中的 extendslayout.pug< /code> 将块变量 添加到您的变量中。

布局中的块变量将被home.pug中的块变量替换。
如果您想向块添加一些变量,您应该在 home.pug 中使用 append Variables

布局.pug

block variables

doctype html
html(lang='en')
    include head.pug

    body(class=bodyClass)
        include header.pug

        block content

        include footer.pug

home.pug

extends layout.pug

block variables
  - let bodyClass = 'page-home';

block content
    p some content in here

In the layout.pug file at top add the block variables and in the home.pug file, after extends layout.pug add the block variables with your variable.

The block variables in layout will be replaced wich your block variables in the home.pug.
If you want add some variables to the block, you should use append variables in the home.pug.

layout.pug

block variables

doctype html
html(lang='en')
    include head.pug

    body(class=bodyClass)
        include header.pug

        block content

        include footer.pug

home.pug

extends layout.pug

block variables
  - let bodyClass = 'page-home';

block content
    p some content in here
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文