I have a YAML file of products:
# Product - Granola Bar
- title : "Granola Bar"
excerpt : "Comes in several amazing varieties including nut, and delicious fruit."
description : "Comes in several amazing varieties including nut, and delicious fruit."
image : "granola-bar.jpg"
cost : "3.50"
discount : "2.50"
stock : "100"
ingredients :
- value : key
# Product - Granola Bar
- title : "Hazelnut Spread"
excerpt : "Chocolate"
description : "Chocolate"
image : "hazelnut-spread.jpg"
cost : "2.50"
discount : "1.50"
stock : "100"
ingredients :
- value : key
When I iterate through these the content is being appended to the previous one's content variable:
"Comes in several amazing varieties including nut, and delicious fruit. 3.50"
"Comes in several amazing varieties including nut, and delicious fruit. 3.50 Chocolate 2.50"
But it should be:
"Comes in several amazing varieties including nut, and delicious fruit. 3.50"
then
"Chocolate 2.50"
I'm using:
-# Create new array for the thumbnails
- thumbnails = []
-# Loop through the array
- data.products.each do | product |
-# Content
- content_for :content do
-# Excerpt
= product.excerpt
-# Cost
= product.cost
- content = yield_content :content
- thumbnails << { :"data-src" => "holder.js/300x200/auto",
:caption => content,
:title => product.title }
I'm not sure what to search for, mutable variables in a loop? I tried putting content = nil
before the loop and inside also to unset it at each pass.
I want to save the content_for
to push into a partial.
This is an image of what is happening. It should obviously not be doubled up in the second thumbnail: