2011-11-14 39 views
2

在基於Haml的Padrino解決方案,我有一個application.haml這樣的:選擇性地使用yield_content在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

在你的主文件,你應該能夠使用content_for?,像這樣:

- if content_for?(:headcontent) 
    = yield_content :headcontent 
- else 
    something else