gpt4 book ai didi

pug - Jade block 的工作原理 - Jade

转载 作者:行者123 更新时间:2023-12-02 03:46:06 25 4
gpt4 key购买 nike

我正在尝试使用 Jade block ,但我的内容未显示。这是我的 index.jade:

//index.jade
extends ../includes/layout

block main-content
section.content
div(ng-view)

它正在像我预期的那样添加 layout 文件。这是该文件:

//layout.jade
doctype html
html
head
link(href="/favicon.ico", rel="shortcut icon",type="image/x-icon")
link(rel="stylesheet", href="/css/bootstrap.css")
link(rel="stylesheet", href="/vendor/toastr/toastr.css")
link(rel="stylesheet", href="/css/site.css")
body(ng-app="app")
h1 Hello Worldd
include scripts

但它不包括我的main.jade:

// main.jade
h1 This is a Partial
h2 {{ myVar }}

或其后的任何代码。这是我第一次使用Jade,所以我很挣扎。另外,当您包含 block 时,-content 是什么?谢谢。

最佳答案

block 是您要插入到从中扩展它的模板中的内容“ block ”。

假设目录布局:

|--views  
|--layout.jade
|--index.jade
|--main.jade

这是使用您的模板的示例:

//layout.jade

doctype html
html
head
link(href="/favicon.ico", rel="shortcut icon",type="image/x-icon")
link(rel="stylesheet", href="/css/bootstrap.css")
link(rel="stylesheet", href="/vendor/toastr/toastr.css")
link(rel="stylesheet", href="/css/site.css")
body(ng-app="app")
h1 Hello Worldd
block content
include scripts

然后从layout.jade扩展的所有其他页面都可以将内容插入到该 block 中:

//index.jade

extends layout
block main-content
section.content
div(ng-view)

//main.jade

extends layout
block content
h1 This is a Partial
h2 {{ myVar }} // which should be: h2= myVar

这将呈现(假设使用 Express):

//index.html

doctype html
html
head
link(href="/favicon.ico", rel="shortcut icon",type="image/x-icon")
link(rel="stylesheet", href="/css/bootstrap.css")
link(rel="stylesheet", href="/vendor/toastr/toastr.css")
link(rel="stylesheet", href="/css/site.css")
body(ng-app="app")
h1 Hello Worldd
section.content
div(ng-view)
include scripts

//main.html

doctype html
html
head
link(href="/favicon.ico", rel="shortcut icon",type="image/x-icon")
link(rel="stylesheet", href="/css/bootstrap.css")
link(rel="stylesheet", href="/vendor/toastr/toastr.css")
link(rel="stylesheet", href="/css/site.css")
body(ng-app="app")
h1 Hello Worldd
h1 This is a Partial
h2 {{ myVar }} // which should be: h2= myVar
include scripts

关于pug - Jade block 的工作原理 - Jade,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21577171/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com