2014-11-21 95 views
1

我在我的_config.yaml中有一個數組。比方說Jekyll數組包含檢查

exclude_pages: [ "/404.html", "/search.html", "/atom.xml", "/rss.xml", "/index.html", "/sitemap.txt" ] 

我想要做的就是在site.pages的頁面循環中排除這些頁面。所以下面是我正在嘗試的代碼。

{% for entry in site.pages %} 
    {% if site.exclude_pages contains entry.url %} 
     <!-- Do Nothing --> 
    {% else %} 
     <!-- Show Page --> 
    {% endif %} 
{% endfor %} 

但不知何故,它沒有發生。這段代碼中所有頁面都被忽略。

任何想法我在這裏失蹤?

+0

嘗試回聲'entry.url'像:'看跌期權 「[#{entry.url}]」 '以確保沒有多餘的無形空間等。 – mudasobwa 2014-11-21 15:55:31

+0

我試過了。問題是'entry.url'顯示'exclude_pages'數組中的確切字符串。但if條件檢查失敗。我試圖顯示條件的布爾輸出。它每次都返回整個數組,而不是任何布爾值。參考屏幕截圖:http://imgur.com/8KR1pnO – 2014-11-22 06:46:22

回答

5

嘗試:

exclude_pages: [ "index.html", "anyfolder/index.html" ] 

然後循環與entry.pathentry.url

{% for entry in site.pages %} 
    {% if site.exclude_pages contains entry.path %} 
     <!-- Do Nothing --> 
    {% else %} 
     <!-- Show Page --> 
    {% endif %} 
{% endfor %} 
+0

在這方面也沒有找到運氣。這個問題是我在上面的評論中提到的。 if條件檢查不返回任何布爾值。而是它返回整個數組本身。請參閱:http://imgur.com/8KR1pnO – 2014-11-22 06:48:47

+0

這兩個代碼在這裏工作。你有github存儲庫嗎? – 2014-11-22 08:18:38

+0

沒關係。得到它的工作。看來,睡眠在我身邊徘徊。這是一個編碼錯誤。 Thanx反正。 :) – 2014-11-23 20:40:46