2011-05-28 79 views
0

我試圖設置Jekyll,以便在帖子列表中的第一篇文章的報價顯示在側邊欄,但我不能完全解決如何做它。在每篇文章的Markdown中,我將YML Front Matter中的引用文本定義爲quote變量。顯示使用Jekyll的第一篇文章中的報價

這是有關提取物我default.html中

<div id="content"> 
    {{ content }} 
</div>  
<div id="sidebar"> 
    <blockquote>{{ page.quote }}</blockquote> 
</div>  

這是我的index.html

--- 
layout: default 
quote: ** Can a variable referencing the first post go here? ** 
--- 
{% for post in site.posts limit:10 %} 
    <h2>{{ post.title }}</h2> 
    <div class="post"> 
    {{ post.content }} 
    </div> 
{% endfor %} 

回答

1

多次試驗之後,我能夠default.html中內解決使用這種液體段的問題:

<div id="sidebar"> 
    <blockquote> 
    {% if page.quote %} 
    {{ page.quote }} 
    {% else %} 
    {{ site.posts.first.quote }} 
    {% endif %} 
    </blockquote> 
</div> 
3
{% for post in site.posts limit:10 %} 
    {% if forloop.index0 == 0 %} 
    {% assign quote = post.quote %} 
    {% endif %} 

    <h2>{{ post.title }}</h2> 
    <div class="post"> 
    {{ post.content }} 
    </div> 
{% endfor %} 

default.html中

<div id="content"> 
    {{ content }} 
</div>  
<div id="sidebar"> 
    <blockquote>{{ quote }}</blockquote> 
</div> 

我不認爲你可以在YML的事情中存儲引用,但這應該得到你想要的。

+0

謝謝,但這並不遺憾的是工作。它看起來像分配給的變量不在** default.html **文件中的範圍內。 – 2011-05-28 17:19:07

+0

我之前使用過這種技術,所以我有點驚訝。你還有YML塊中的'quote'嗎?您可以嘗試將'page.quote'更改爲'quote'。 – 2011-05-28 17:26:35

+0

不,我沒有YML塊中的「quote」。我應該有嗎? – 2011-05-28 17:40:44

相關問題