2013-06-03 27 views
2

我正在使用Jekyll作爲學術網站。我正在使用publication類別的帖子來表示出版物。已經寫入由美國最新校長的論文,例如,將類似於此(除了其他一些變量的不相關的這個問題):用站點變量替換列表中的前置元素

--- 
categories: publications 
layout: publication 
title: "This is the paper Title" 
authors: [bomama, gwbush, bclinton] 
--- 

我特別想在元素例如,將作者列表轉換爲某些預定義的URL,例如可以將其指定爲站點變量。我希望這樣做,所以當作者更改機構(因此,他/她的網頁網址)時,我不必更改每個出版物(=發佈)。

謝謝!

回答

4

_config.yml你可以添加你自己的命名空間爲用戶定義的變量:在作者

app: 
    authors: 
    bomama: 
     name: 'Barack Obama' 
     url: 'http://barackobama.com' 
    gwbush: 
     name: 'George W. Bush' 
     url: 'http://georgewbush.com' 

然後在模板中環和合並在用戶定義的app:authors

{% for id in page.authors %} 

    {% if site.app.authors[id] %} 
    <a href="{{ site.app.authors[id]['url'] }}">{{ site.app.authors[id]['name'] }}</a> 
    {% endif %} 

{% endfor %} 

輸出:

<a href="http://barackobama.com">Barack Obama</a> 

<a href="http://georgewbush.com">George W. Bush</a> 
+1

謝謝!我不知道我可以使用'authors [id]'構造。 – themiurgo

+0

太棒了!謝謝 :) – Tex