I have a YAML database with data in the following format:
- product:
name: Apples
- product:
name: Grapes
How can I update it so each product is assigned to a category, then on my page I can have an unordered list the products under a category heading?
For example:
Fruit
*Apples
*Grapes
Vegetables
*Tomatoes
*Broccoli
I tried searching for an example of something like this, but couldn’t find anything. Is it possible to do something like this?
- category:
name: fruit
- product:
name: Apples
- product:
name: Grapes
- category:
name: vegetables
- product:
name: Tomatoes
- product:
name: Broccoli
I’d suggest two schemes, the first groups all products together:
The other scheme would be using on group for each type of product
To actually display this you would just load the yaml data with something like (forgive me if this has changed… it’s been a while since I used yaml):
data is essentially just a ruby hash so you can display whatever you like by traversing it.
EDIT:
If the second option is what you want. Try the following:
Output should be:
If you want to output html, then modify it to something like:
You can see the differences to add the html formatting is very simple and you should be able to further modify this to your needs.