【问题标题】:Jekyll: Using values from _config.yml in SCSSJekyll:在 SCSS 中使用 _config.yml 中的值
【发布时间】:2015-12-14 18:46:21
【问题描述】:

在我的 Jekyll 项目中,我的 _config.yml 文件中有以下内容:

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

assets/css/colors.scss 中,我想为颜色创建类,如下所示:

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

当我这样做时,我收到以下错误:

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

有没有办法让 Liquid 处理 SCSS 中 _config.yml 文件中的值?

【问题讨论】:

    标签: sass jekyll liquid


    【解决方案1】:

    如果你想让 Jekyll 处理你的 scss 文件,你必须给它添加一个前端。

    这行得通:

    ---
    # empty front matter
    ---
    @charset "utf-8";
    
    {% for color in site.colors %}
    .{{ color.name }} {
      color: {{ color.hex }};
    }
    {% endfor %}
    

    【讨论】:

    • 谢谢,这就行了。 Liquid 标签在 SCSS 部分中似乎不起作用,但这是解决的基本限制。
    • 所以,也许你可以批准这个答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多