Profitability for several blocks

I am writing a small Sinatra-based application and would like each view to be able to insert various elements into the layout, such as a page titleor CSS / javascript sitelinks in head.

Currently my layout (erb) looks like this (simplified):

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

Instead of having a headline and CSS / JS links hardcoded, I would like to achieve something in this direction:

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

And be able to define content for these blocks from each view.

Is this possible, and if so, how can I do this?

+5
source share
3 answers

Railscamp , , , sinatra-content-for. , .

+4

"content_for" Rails Sinatra, ERB, Haml:

http://github.com/kematzy/sinatra-outputbuffer

+3

You can just use @stylesheet in a ruby ​​file

0
source

All Articles