2016-05-31 9 views
0

私のサイトにのコンポーネントのコレクションがありますが、それらは.ymlファイルの変数で指定されている内容で埋められています。Jekyll変数を上書きする方法

site.components/button.html

--- 
title: Button 
--- 
{% assign yml = 'sample' %} 
<a href="#">{{ site.data.[yml].button }}</a> 

データ/ sample.yml

#variables 
button: Click Me 

私は変数がうまく動作URL /button.htmlを開きます。

#Page Output 
<html> 
    <a href="#">Click Me</a> 
</html> 

Q:コンポーネントがページで使用されているときに変数を上書きする方法はありますか?例えば:

--- 
title: A Sample Page 
--- 
{% assign yml = 'content'%} 
{{ site.components | where:"title" : "Button" }} 

データ/ content.yml

#variables 
button: Join Now 

#Page Output <html> <a href="#">Join Now</a> </html> 

/sample-page.htmlコンポーネントが含まれていません。

答えて

2

回答はNOです。

{{ site.components | where:"title" : "Button" }}を実行すると、タイトルに一致するJekyllドキュメントの配列が取得されます。それらの文書はすでに液体解析済みです。あなたはジキルにそれらを再び解析するように指示することはできません。

唯一の方法は、includesを使用して変数を渡すことです。

_includes/button.html

<a href="#">{{ site.data.[include.text].button }}</a> 

_components/button.html

--- 
title: Button 
--- 
{% include button.html text='sample' %} 

サンプルpage.html

--- 
title: A Sample Page 
--- 
{% include button.html text='content' %} 
関連する問題