Oh, I see! There’s a couple of ways you could do that.
One way is to use content_for
.
Inside carrot_soup.md.erb
(note the added .erb
extension):
---
title: Carrot Soup
---
<% content_for :ingredients do %>
<ul>
<li>Carrots – 0.2oz</li>
<li>Onion – 0.1oz</li>
</ul>
<% end %>
Instructions for the recipe go here.
Inside your layout:
…
<body>
<div id="recipe">
<h1><%= current_page.data.title %></h1>
<%= yield %>
<div class="sidebar">
<%= yield_content :ingredients %>
</div>
</div>
<body>
…
One restriction with this approach would be that you would have to keep keep everything within content_for
in HTML.
Another approach would be to keep the page’s ingredients in the frontmatter. Again, inside carrot_soup.md
:
---
title: Carrot Soup
ingredients:
- "Carrot: 0.2oz"
- "Onion: 0.1oz"
- Salt and pepper
---
Instructions go here.
Inside your layout:
…
<body>
<div id="recipe">
<h1><%= current_page.data.title %></h1>
<%= yield %>
<div class="sidebar">
<ul>
<% current_page.data.ingredients.each do |ingredient| %>
<li><%= ingredient %></li>
<% end %>
</ul>
</div>
</div>
<body>
…
In the frontmatter example above, we’ve turned the list of ingredients into an array, but we could also break it down by ingredient and amount:
---
title: Carrot Soup
ingredients:
Carrot: 0.2oz
Onion: 0.1oz
"Salt and pepper": a pinch
---
<ul>
<% current_page.data.ingredients.each do |ingredient, amount| %>
<li>
<strong><%= ingredient %>:</strong>
<%= amount %>
</li>
<% end %>
</ul>
Hope that helps!