3
votes

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

1 Answers

5
votes

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.