Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Variables Jekyll Liquid

I would like to use dynamic variables for my jekyll + liquid installation. I want to dynamically access the _config.yml file using the dynamic variable names.

It is best explained with an example:

Page:

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

Default Layout:

{{ 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."

So how can I access the _config.yml with a dynamic variable name?

like image 868
Hendrik Avatar asked May 20 '12 15:05

Hendrik


1 Answers

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

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.

like image 115
Alan W. Smith Avatar answered Oct 14 '22 14:10

Alan W. Smith