×
关于

开始旅程

快速指南安装基本用法目录结构配置

编辑内容

头信息撰写博客使用草稿创建页面常用变量Data FilesAssets博客迁移

定制

模板永久链接分页功能插件附加功能

部署

GitHub Pages部署方法

杂项

常见问题使用 Jekyll 的站点相关资源升级

元信息

贡献

Data Files


In addition to the built-in variables available from Jekyll, you can specify your own custom data that can be accessed via the Liquid templating system.

Jekyll supports loading data from YAML files located in the _data directory.

This powerful feature allows you to avoid repetition in your templates and to set site specific options without changing _config.yml.

Plugins/themes can also leverage Data Files to set configuration variables.

The Data Folder

As explained on the directory structure page, the _data folder is where you can store additional data for Jekyll to use when generating your site. These files must be YAML files (using either the .yml or .yaml extension) and they will be accessible viasite.data.

Example: List of members

Here is a basic example of using Data Files to avoid copy-pasting large chunks of code in your Jekyll templates:

In _data/members.yml:

- name: Tom Preston-Werner
  github: mojombo

- name: Parker Moore
  github: parkr

- name: Liu Fengyun
  github: liufengyun

This data can be accessed via site.data.members(notice that the filename determines the variable name).

You can now render the list of members in a template:

<ul>
{% for member in site.data.members %}
  <li>
    <a href="https://github.com/{{ member.github }}">
      {{ member.name }}
    </a>
  </li>
{% endfor %}
</ul>

分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)