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

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

This is what I want to do, but I cannot get it to work. Can this be done?

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 %} 
+2
source share
1 answer

While you apparently cannot use Liquid conditionals and environment variables (as in many other build scripts), you can make selective overrides using the second yml file:

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

with _dev.yml :

 # overrides title in _config.yml title: "My Website (dev mode)" # see my styles uncompressed for dev work sass: style: uncompressed 

Perhaps this suits your needs ...

+1
source

Source: https://habr.com/ru/post/1247951/


All Articles