首页 > 解决方案 > 渲染哈巴狗扩展/块时遇到问题?

问题描述

块内容标题未显示在我的 html 页面上。我已经浏览了附近的一些教程和其他 stackoverflow 文章,因为我可以告诉我遵循正确的语法。我确定我错过了一些东西,但我找不到它。如果可以的话请帮忙。

我在代码中留下了评论。我尝试更改块的位置以及代码的缩进。我还尝试按照其他文章中的建议添加附加和前置。以及将标题更改为标题以确保我没有冲突。

doctype html
html
body
    block header // have tried with append & prepend and tried it below h1 tag
        h1 Index Page
        p This is the index page

```header.pug:
extends index

block header
    label page1 
    label page2

I am not getting an errors with this code. It is not displaying any of the content from header.pug.

标签: pug

解决方案


我认为您对扩展的工作方式感到困惑。包含extends声明的文件就是页面,它只是使用它扩展的另一个文件中的标记。

我修改了@kmgt 的答案来说明这一原则。请注意每个文件的不同名称。

包装器.pug

doctype html
html
  head
  body

    include header

    block content

头文件.pug

label page1 
label page2

指数.pug

extends wrapper

append content
  h1 Index Page
  p This is the index page

关于.pug

extends wrapper

append content
  h1 About Page
  p This is the about page

推荐阅读