Passing blocks through render('partialname')

How can I capture the block that I pass through a partial. I want to be able to do something like:

<%= render 'shared/partialname' do %>   Misc code / text <% end %>

Then I want to display that block at a specific place in that partial. I could do this if I created a method. But I want to know how it works with partials.

Brent <wejrowski@...> writes:

How can I capture the block that I pass through a partial. I want to be able to do something like:

<%= render 'shared/partialname' do %>   Misc code / text <% end %>

Then I want to display that block at a specific place in that partial. I could do this if I created a method. But I want to know how it works with partials.

Placing <%= yield %> in your partial will determine where blocks are rendered:

#app/views/shared/partialname.html.erb <h1>This is a partial heading</a> <%= yield %>

Should result in:

<h1>This is a partial heading</a> Misc code / text

That's exactly what I tried. I've tried multiple variations too but I can't seem to get it.

This works for me:

views/layouts/application.html.erb:

<!DOCTYPE html> <html> <head>   <title><%= @title %></title>   <%= csrf_meta_tag %> </head> <body>

<%= yield %>

</body> </html>

views/users/new.html.erb:

<h1>Users#new</h1> <p>Find me in app/views/users/new.html.erb</p>

<%= render :layout => 'shared/awesome', :locals => {:greeting => 'hello'} do %>   <div>world</div> <% end %>

views/shared/_awesome.html.erb:

<div><%= greeting %></div> <%= yield %>

http://localhost:3000/users/new View Source:

<!DOCTYPE html> <html> <head>   <title>Sign up</title>   <meta name="csrf-param" content="authenticity_token"/> <meta name="csrf-token" content="3S4d6FpN0hkzvwCHEbNG/OR34UBwqOTlhDtwL5VIXd4="/> </head> <body>

<h1>Users#new</h1> <p>Find me in app/views/users/new.html.erb</p> <div>hello</div>

  <div>world</div>

</body> </html>

Darn you know what it was.. I was doing render 'partialname'... instead of render :layout=>'partialname'

Thanks! BTW anyone know what the difference is there? ^

Brent wrote in post #1014240:

Darn you know what it was.. I was doing render 'partialname'... instead of render :layout=>'partialname'

Yah. That was the point of my post.