Using Rails 2.3.8. My site displays reviews. Depending on what context the review is shown in the review's heading and thumbnail change.
I'm trying to share a layout across several review partials. Each partial would define a few snippets of HTML to be used in the layout.
Is this possible? I've tried several variations of the following:
#layout
.review[review] .thumb = yield :thumb .details %h4 = yield :heading %div Rest of layout.....
Using this renders index twice (index uses a layout too):
# index.html.haml %h2 Product reviews = image_tag(@product.url) = render :layout => @reviews, :locals => { :product => @product } do
section>
- if section == :thumb thumb stuff
Using this causes content to be appended upon each iteration of the content_for blocks:
# index.html.haml - @reviews.each do |review| - content_for :heading do Heading stuff... - content_for :thumb do Thumb stuff...
= render :partial => "shared/review", :object => review, :locals => { :product => @product }
I know I can make the blocks locals:
= render :partial => "review", :object => review, :locals => { :product => @product, :heading => link_to(image_tag(@product.url), @product.name) }
But this gets ugly as the HTML becomes more complex. Yes, I can use helpers, but I'd prefer to keep the somewhat larger HTML snippets in the templates instead of doing things like:
content_tag :div, :class => dom_id(@user) do content_tag :span, "xxxxx" # more code... end