2017-07-07 72 views
0

我有一個category.html頁面,它將循環訪問某個類別的帖子。Jekyll中的類別頁面

{% for post in site.categories.tech %} 

我想要顯示當用戶點擊

{{ post.categories }} 
這是從顯示的所有職位的迴路中產生

index.html頁。

{% for post in site.posts %} 

我需要{{ post.categories }}變量替換.techcategories.html這樣

{% for category in site.categories.{{ post.categories }} %} 

我不知道如何將變量從index.htmlcategories.html

回答

0

網站類別傳遞的是對象,其中每個鍵都是類別名稱。所以

{{ site.categories }} 

輸出是這樣的:

{ 
    "Category name" => [#, #, #, #, #, #, #], 
    "Another category name" => [#, #, #, #, #, #, #], 
    ... 
} 

因此,方括號應該這樣做。因此,如果在您的index.html的前不管你有

--- 
categories: tech 
--- 

下面的代碼將呈現下的高科技品類您所有的帖子。

{% for post in site.categories[post.categories] %} 
    {{ post }} 
{% endfor %} 

當然,如果您在前面的問題中有多個類別,但是我不知道您的用例,那麼這將不起作用。

+0

如何傳遞從index.html中點擊的變量。如果用戶點擊了tech,我怎麼才能將它傳遞給categories.html並將值放在[post.categories] – juscuizon

+0

裏我不明白「clicked變量」是什麼意思。請發佈一個示例,說明如何在'index.html'中定義該變量。 –