Jekyll: Using values from _config.yml in SCSS

烈酒焚心 提交于 2019-12-24 15:35:53

问题


In my Jekyll project, I have the following in my _config.yml file:

colors:
  - name: red
    hex: '#FF0000'
  - name: yellow
    hex: '#FFFF00'
  - name: blue
    hex: '#0000FF'

In assets/css/colors.scss, I want to create classes for the colors as follows:

{% for color in site.colors %}
.{{ color.name }} {
  color: {{ color.hex }};
}
{% endfor %}

When I do so, I get the following error:

Error in _assets/css/background-test.scss:6 Invalid CSS after "}": expected selector or at-rule, was "{% for color in..." 
  Liquid Exception: Invalid CSS after "}": expected selector or at-rule, was "{% for color in..." in _includes/head.html, included in _layouts/default.html
jekyll 3.0.1 | Error:  Invalid CSS after "}": expected selector or at-rule, was "{% for color in..."

Is there a way to get Liquid to process the values from the _config.yml file in the SCSS?


回答1:


If you want Jekyll to process your scss file you must add a front matter to it.

This works :

---
# empty front matter
---
@charset "utf-8";

{% for color in site.colors %}
.{{ color.name }} {
  color: {{ color.hex }};
}
{% endfor %}


来源:https://stackoverflow.com/questions/34274368/jekyll-using-values-from-config-yml-in-scss

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