问题描述
我想在我的jekyll +液体安装中使用动态变量.我想使用动态变量动态访问_config.yml文件名称.
I would like to use dynamic variables for my jekyll + liquid installation.I want to dynamically access the _config.yml file using the dynamic variablenames.
最好用一个例子来解释:
It is best explained with an example:
页面:
---
layout: default
title: title_homepage
---
默认布局:
{{ site.locales[site.default_locale].page.title }}
_config.yml:
default_locale: "en"
locales:
en:
title_homepage: "This is my homepage title!"
pirate:
title_homepage: "Yaaawwwr. Homepage title."
那么如何使用动态变量名访问_config.yml?
So how can I access the _config.yml with a dynamic variable name?
推荐答案
您要提取的标题来自站点配置.不是页面本身.您需要做的就是将默认布局"列表中的调用更改为此:
The title that you want to pull is form the site config. Not the page itself. All you need to do is change the call in your Default Layout listing to this:
{{ site.locales[site.default_locale].title_homepage }}
设置default_locale: "en"
时,输出将为这是我的首页标题!".当您将_config.yml文件更新为default_locale: "pirate"
时,输出将为"Yaaawwwr.Homepage title".我已经在Jekyll 0.11.2上对其进行了测试,它可以按预期工作.
When you set default_locale: "en"
the output will be "This is my homepage title!". When you update the _config.yml file to default_locale: "pirate"
, the output will be "Yaaawwwr. Homepage title." I've tested this on Jekyll 0.11.2 and it works as expected.
这篇关于动态变量Jekyll Liquid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!