Search code examples
rubymiddleman

Middleman: How can I get the current article title?


When generating a simple blog in Middleman using the "middleman-blog" extension I get a the layout file which simply yields the content of the post.

What I want is to get the title of the current post and display that.

What I have right now:

<% blog.articles.each do |article| %>
    <%= link_to article.title, article %>
<% end %>

This loops through every post title even though only the single post content is displayed. So it outputs something like this for the url /post-title-one


Post Title One Post Title Two Post Title Three

"only the content of post title one"


I want to try something like

<% blog.articles.each do |article| %>
    <%= link_to current_article.title, article %>
<% end %>

But it just randomly spits out two page titles.


Solution

  • If you want to print the current article's title just use <%= current_article.title %>.