content_for
is used to capture content that is used in a different place.
If you have yield_content :title
in your application layout and you set it in the currently rendered partial:
# index.haml
- content_for :title, "I'm on the index page"
Your example should NOT use content_for
at all. It should just render the strings into the output:
- data.products.each do |product|
= product.excerpt
= product.cost
If you want to use that output in a img_tag
helper or something like that, than use a helper method to generate the content or put it into its own partial if the logic is more complex.
You can also assign new variables in the view code and use them later on:
- caption = "#{product.excerpt} #{product.cost}"
I don't see a need for anything like that in your example at all. Maybe that's because you actually never use "thumbnails" anywhere.