问题
In Jekyll, is there any way to access the rendered content of a post from another page?
Here's the scenario: Suppose I wanted to create a blog index page listing a bunch of posts. Each post uses a different layout (text, photo, tweet, etc). Is there a way to get Jekyll to render each post with the layout specified inside of that post and then hand me the rendered content so that I can put it into a summary page?
(I'm 97% sure I saw this exact question asked and answered somewhere here on Stack Overflow, but I cannot for the life of me find it. If anyone could point me to it, I would be most grateful! Of course, original solutions are also appreciated!)
(Edited to make it clear that I want dynamic access to rendered content. Not after the fact in the _sites directory, but while building the site.)
回答1:
post.layout
is the layout of one post, it's default is post
So, i think, you can do this
{% for post in site.posts %}
{% if post.layout == 'layout1' %}
do something, such as put it into an array ...
{% else if post.layout == 'layout2' %} // here 'else if' may not correct liquid syntax
do something else
{% endif %}
{% endfor %}
来源:https://stackoverflow.com/questions/18157260/is-there-a-way-to-access-rendered-content-in-jekyll