Jekyll Liquid - accessing _config.yml dynamically

烈酒焚心 提交于 2019-12-01 22:58:01

问题


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

It is best explained with an example:

Page:

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

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

Default Layout:

page.title = "title_homepage"

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

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

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}}

回答1:


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
---

Which you can retrieve with {{ page.title }} ...

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

(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.



来源:https://stackoverflow.com/questions/10750755/jekyll-liquid-accessing-config-yml-dynamically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!