我如何动态地在Jekyll _config.yml中更改变量? [英] How can I change a variable in Jekyll _config.yml dynamically?

查看:949
本文介绍了我如何动态地在Jekyll _config.yml中更改变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在开发一个Jekyll项目,我需要在_config.yml中添加一个变量,以便从模板代码中动态更改。

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?

在_config.yml中:

In _config.yml:

my_var: "value"

在template.html中:

In template.html:

{% site.my_var = "newvalue" %}

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


推荐答案

虽然您显然无法使用和环境变量(和许多其他构建脚本一样),您可以使用第二个yml文件进行选择性覆盖:

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

_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...

这篇关于我如何动态地在Jekyll _config.yml中更改变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆