为什么我的苗条模板出错?

时间:2014-08-06 08:36:49

标签: html ruby-on-rails ruby sinatra slim-lang

我的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)

1 个答案:

答案 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