How can I change a variable in Jekyll _config.yml dynamically?

那年仲夏 提交于 2019-12-08 02:53:14

问题


Hi I'm working on a Jekyll project and I need to put a variable in _config.yml that I want to change dynamically from the template code.

This is what I want to do, but I can't get it to work. Is it possible to do this?

In _config.yml:

my_var: "value"

In template.html:

{% site.my_var = "newvalue" %}

{% case site.my_var %}
  {% when "value" %}
    //do this
  {% when "newvalue" %}
   //do this instead
{% endcase %}

回答1:


While you apparently cannot use Liquid conditionals nor Environment Variables (as in many other build scripts), you can do a selective overrides with a second yml file:

$> bundle exec jekyll serve --drafts --incremental --config _config.yml,_dev.yml

with a _dev.yml:

# overrides title in _config.yml
title: "My Website (dev mode)"

# see my styles uncompressed for dev work
sass:
    style: uncompressed

Perhaps that fits your needs...



来源:https://stackoverflow.com/questions/18211029/how-can-i-change-a-variable-in-jekyll-config-yml-dynamically

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