有没有办法在Jekyll中访问渲染的内容? [英] Is there a way to access rendered content in Jekyll?
问题描述
在Jekyll中,有什么方法可以从另一个页面访问帖子的渲染内容?
In Jekyll, is there any way to access the rendered content of a post from another page?
这里是场景:假设我想创建一个博客索引页面,列出一堆帖子.每个帖子使用不同的布局(文本,照片,tweet等).有没有办法让Jekyll用该帖子内部指定的布局呈现每个帖子,然后将呈现的内容交给我,以便我可以将其放入摘要页面?
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?
(我97%的确定我在Stack Overflow上的某个地方看到这个确切的问题被问到并回答了,但是我一生无法找到它.如果有人能指出我的想法,我将不胜感激!当然,原始的解决方案也将不胜感激!)
(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!)
(已编辑,以明确表明我希望动态地访问呈现的内容.不是在_sites目录中,而是在构建网站时.)
(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.)
推荐答案
post.layout
是一篇文章的布局,默认为post
所以,我想,你可以做到
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 %}
这篇关于有没有办法在Jekyll中访问渲染的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!