Jekyll Liquid-动态访问_config.yml [英] Jekyll Liquid - accessing _config.yml dynamically

查看:74
本文介绍了Jekyll Liquid-动态访问_config.yml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要使我的应用程序国际化,我需要能够动态访问YAML文件中的条目.

For internationalizing my app I need to be able to dynamically access entries in a YAML file.

最好用一个例子来解释:

It is best explained with an example:

页面:

---
layout: default
title: title_homepage
---

这将允许访问默认布局模板中的title_homepage变量:

This will then allow access to the title_homepage variable in the Default Layout Template:

默认布局:

page.title ="title_homepage"

page.title = "title_homepage"

现在通常我会这样访问我的_config.yml文件:

Now normally I would access my _config.yml file like this:

{{ site.locales[site.default_locale].variable }}

但是,现在要使其正常工作,我需要使用page.title的值访问_config.yml.这将不起作用:

However, now for this to work, I need to access the _config.yml with the value of page.title. This will not work:

{{ site.locales[site.default_locale].page.title }}

我需要以下内容(伪代码):

I need the following (pseudo code):

{{ site.locales[site.default_locale].#{value of page.title}}

推荐答案

使用您的var设置方式,这会有点像

With the way your vars are set, it would be something alog the lines of

{{ site.locales[site.default_locale][page.title] }}

问题是, ...我真的不明白这样做的意义.假设您的页面是英文页面.然后应在页面中定义语言环境,标题也应定义!

The thing is, ... I don't really see the point of doing this. Let's say your page is the english page. The locale should then be defined within the page, and so should your title!

---
locale: en
title: My Wonderful Page
---

您可以使用{{ page.title }} ...

将标题放入_config.yml文件有什么意义?

What could be the point of putting the title into the _config.yml file?

(编辑)很好,除非您要在另一个页面/帖子中访问page.title,在这种情况下,您别无选择,只能将其放入_config.yml.

(edit) well unless you want to access page.title when in another page/post, in this case you have no choice but to put it into _config.yml.

这篇关于Jekyll Liquid-动态访问_config.yml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆