您好,我正在做一个 Jekyll 项目,我需要在 _config.yml 中放置一个变量,我想从模板代码中动态更改它。
这是我想做的,但我做不到。可以这样做吗?
在 _config.yml 中:
my_var: "value"
在 template.html 中:
{% site.my_var = "newvalue" %}
{% case site.my_var %}
{% when "value" %}
//do this
{% when "newvalue" %}
//do this instead
{% endcase %}
最佳答案
虽然您显然不能使用 Liquid conditionals也不是环境变量(与许多其他构建脚本一样),您可以使用第二个 yml 文件进行选择性覆盖:
$> bundle exec jekyll serve --drafts --incremental --config _config.yml,_dev.yml
使用_dev.yml
:
# overrides title in _config.yml
title: "My Website (dev mode)"
# see my styles uncompressed for dev work
sass:
style: uncompressed
也许这符合您的需求...
关于html - 如何动态更改 Jekyll _config.yml 中的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18211029/