Is there a way to access rendered content in Jekyll?

喜欢而已 提交于 2019-12-25 05:24:26

问题


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.layoutis 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!