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.
当使用“Middleman -blog”扩展在Middleman中生成一个简单的blog时,我得到的是布局文件,它只生成文章的内容。
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标题,即使只显示单个post内容。它为url /post-title- 1输出类似的东西
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.
但它只是随机地吐出两页标题。
2 个解决方案
#1
6
If you want to print the current article's title just use <%= current_article.title %>
.
如果您想打印当前文章的标题,只需使用<%= current_article。标题% >。
#2
1
I'm not quite sure what you're asking. The first block of code you gave is intended to iterate through each article in the blog and generate a link where the link text is the article's title and the target is the article. I would assume that you want to simply link to the current article, since you're on its content page.
我不太清楚你在问什么。您给出的第一个代码块的目的是在博客中遍历每一篇文章,并生成链接文本是文章标题的链接,而目标是文章。我假设您只想链接到当前的文章,因为您在它的内容页面上。
<%= link_to current_article.title, current_article %>
That should get the job done.
这应该能完成任务。
#1
6
If you want to print the current article's title just use <%= current_article.title %>
.
如果您想打印当前文章的标题,只需使用<%= current_article。标题% >。
#2
1
I'm not quite sure what you're asking. The first block of code you gave is intended to iterate through each article in the blog and generate a link where the link text is the article's title and the target is the article. I would assume that you want to simply link to the current article, since you're on its content page.
我不太清楚你在问什么。您给出的第一个代码块的目的是在博客中遍历每一篇文章,并生成链接文本是文章标题的链接,而目标是文章。我假设您只想链接到当前的文章,因为您在它的内容页面上。
<%= link_to current_article.title, current_article %>
That should get the job done.
这应该能完成任务。