Middleman Snippets

List all child pages

1
2
3
4
5
<ul>
<% current_page.children.each do |page| %>
  <li><%= link_to page.data.title, page.url %></li>
<% end %>
</ul>

List pages in a specific directory with a specific tag

1
2
3
4
5
6
7
<% sitemap.resources.each do |page| %>
  <% if page.url =~ /^(\/styleguide\/)/ && page.data.tags == 'pattern' %>

    <br><%= link_to page.data.title, page.url %>

  <% end %>
<% end %>

Art direction and page-specific CSS & JS

In layout file

1
2
3
4
// in the head
<%= yield_content :css %>
// at the bottom
<%= yield_content :js %>

On the page

1
2
3
4
5
6
7
8
9
10
11
12
13
<% content_for :css do %>
<style>

</style>
<% end %>

<% content_for :js do %>
<script>
  (function($){

  })(jQuery);
</script>
<% end %>

Title and (meta) description

1
2
<title><%= (current_page.data.page_title || current_page.data.title).titleize %> | <%= data.site.name %> </title>
<meta content="<%= current_page.data.description || data.site.description %>" name="description" />

Body classes

1
<body class="<%= page_classes %> <%= current_page.data.layout %>">