0
votes

Im trying to output front matter variables depending on the current Jekyll environment.

For example, if the current environment is dev I would like the variable dev to be displayed:

---
something:
  dev: "Some text"
  production: "Other text
---

I'm trying to access the variable dev with the following method and I get no result:

{{ page.something.jekyll.environment }}

Is there a better way to do this?

2

2 Answers

2
votes

I don't think you can access front matter in this way.

Instead, you coud assign the dev variable in your html template, with the environment as a conditional:

---
layout: default
---
{% if jekyll.environment == "dev" %}
{% assign dev = "this is dev" %}
{% endif %}

<div id="page-content">
{{dev}}
...
</div>

You could also directly wrap the relevant element in an if statement in the template.

1
votes

The right syntax is : {{ page.something[jekyll.environment] }}.

Note that locally jekyll.environment is "development" and not "dev".