【问题标题】:How do I get Jekyll scope/value pairs from config.yml如何从 config.yml 获取 Jekyll 范围/值对
【发布时间】:2015-07-31 23:03:11
【问题描述】:

如何将 Jekyll _config.yml 文件中的默认范围/值提取到默认布局中?

这是 _config.yml 的一部分

# default settings
defaults:
  -
    scope:
      path: "" # an empty string here means all files in the project
      type: posts
    values:
      author: ME
      layout: post
      class: article

我想打印一些简单的东西,例如 {{ site.defaults.scope.type }}

【问题讨论】:

  • 您可以获取site.defaults 数组,但要知道用于为某些帖子或页面设置默认值的标准是什么会很棘手。您最好依靠专门为模式设置的values,并使用page.myValue 获取它们。
  • 谢谢大卫。我正在使用 site.defaults 但它抓取了整个数组,我无法单独获取值。我试图避免使用 page.value,因为我必须浏览大量页面。你会不会碰巧知道如何在上面的例子中拉取类值?

标签: jekyll


【解决方案1】:

您可以通过在符合指定路径和类型的页面中使用page.class 来简单地获取值class。例如:

config.yml

defaults:
  -
    scope:
      path: ""
      type: posts
    values:
      class: a post
  -
    scope:
      path: ""
      type: not_posts
    values:
      class: not a post

_posts/****-**-**-post.html

---
layout: post
---
{{ page.class }}

输出

a post

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多