我试图使用一个Jade块,我的内容没有显示.这是我的index.jade:
//index.jade
extends ../includes/layout
block main-content
section.content
div(ng-view)
Run Code Online (Sandbox Code Playgroud)
它正在添加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
Run Code Online (Sandbox Code Playgroud)
但它不包括我的main.jade:
// main.jade
h1 This is a Partial
h2 {{ myVar }}
Run Code Online (Sandbox Code Playgroud)
或其后的任何代码.这是我第一次使用,Jade所以我很挣扎.另外,-content当你包括一个时,它是block什么?谢谢.
块是您要插入到扩展它的模板的内容的"块".
假设目录布局:
|--views
|--layout.jade
|--index.jade
|--main.jade
Run Code Online (Sandbox Code Playgroud)
以下是使用模板的示例:
//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
Run Code Online (Sandbox Code Playgroud)
然后,从layout.jade扩展的所有其他页面都可以将内容插入到该块中:
//index.jade
extends layout
block main-content
section.content
div(ng-view)
Run Code Online (Sandbox Code Playgroud)
//main.jade
extends layout
block content
h1 This is a Partial
h2 {{ myVar }} // which should be: h2= myVar
Run Code Online (Sandbox Code Playgroud)
这将呈现(假设使用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
Run Code Online (Sandbox Code Playgroud)
//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
Run Code Online (Sandbox Code Playgroud)