我的layout.slim视图是:
doctype html
html
head
meta charset="utf-8"
meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"
title= "Title"
meta name="description" content=""
meta name="author" content=""
meta name="keywords" content=""
meta name="viewport" content="width=device-width, initial-scale=1.0"
link href='/css/base.css' rel='stylesheet' type='text/css'
body
== yield
我的main.slim视图是
== slim :layout
h1 hello
h2 world
它渲染得很好,但我渲染的html将head属性复制到body标签中!它看起来像这样:
html
head
meta..
meta..
title ...
...
body
meta..
meta..
title ...
...
<h1>Hello</h1>
...
为什么会那样?
(顺便说一下,我使用的原因&#34; == slim:layout&#34;是启用模板的嵌套继承(即layout.slim - &gt; main.slim - &gt; form.slim)
答案 0 :(得分:1)
您的布局中有错误的缩进,body
应位于html
内,而== yield
位于正文内,请改为:
doctype html
html
head
meta charset="utf-8"
meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"
title= "Title"
meta name="description" content=""
meta name="author" content=""
meta name="keywords" content=""
meta name="viewport" content="width=device-width, initial-scale=1.0"
link href='/css/base.css' rel='stylesheet' type='text/css'
body
== yield
使用此:
doctype html
html
head
meta charset="utf-8"
meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"
title= "Title"
meta name="description" content=""
meta name="author" content=""
meta name="keywords" content=""
meta name="viewport" content="width=device-width, initial-scale=1.0"
link href='/css/base.css' rel='stylesheet' type='text/css'
body
== yield