2

在基于 Haml 的 Padrino 解决方案中,我有一个application.haml这样的:

!!!
%html
  %head
    %title "blah"
%body
  #header
    = yield_content :headcontent
  #container
    ...

对于:headcontent,在我的页面(例如index.haml)我有

- content_for :headcontent do
  #headcontent
     %h2= "Index header stuff"
#content
  ...

我想要做的是使内容页面index.haml可以选择指定- content for :headcontent. 那就是我想application.haml包含一些仅在页面不执行时才呈现的默认值:headcontent- content for :headcontent

我该怎么做呢?

4

1 回答 1

4

在您的主文件中,您应该可以使用content_for?,如下所示:

- if content_for?(:headcontent)
    = yield_content :headcontent
- else
    something else
于 2011-11-14T19:30:35.887 回答