我正在編寫一個基於Sinatra的小應用程序,並希望每個視圖都能夠在佈局中插入各種項目,例如頁面title
或head
中額外的CSS/javascript參考。針對多個塊的收益率
目前我的佈局(ERB)看起來像這樣(簡化):
<html>
<head>
<title>Hard Coded Title Here</title>
<link rel="stylesheet" ... />
</head>
<body>
<h1>Hard Coded Title Here</h1>
<div id="content">
<%= yield %>
</div>
</body>
</html>
,而不是使標題和CSS/JS引用硬編碼,我想沿着這些線路實現的東西:
<html>
<head>
<title><%= yield :title %></title>
<link rel="stylesheet" ... />
<%= yield :more_head_refs %>
</head>
<body>
<h1><%= yield :title %></h1>
<div id="content">
<%= yield %>
</div>
</body>
</html>
並且能夠從每個視圖內爲這些塊定義內容。
這是可能的,如果是的話,我會怎麼做呢?
太棒了,看起來像我正在尋找的東西。謝謝。 – 2009-12-05 10:48:46
隨着項目[sinatra-content-for2](http://rubygems.org/gems/sinatra-content-for2)繼續開發。 – gioele 2011-12-07 16:43:50