Eleventy(11ty) logo Eleventy
The possum is Eleventy’s mascot
Eleventy 中文文档
Menu
Eleventy 5.81s
Gatsby 43.36s

全局数据文件(Data File)预处理

ERROR:
该功能已废弃:该功能在 Eleventy 2.0 版本中已被删除。你可以改用 JavaScript 数据文件(Data Files)经计算的数据(Computed Data) 来替代此功能。

The dir.data global data files run through this template engine before transforming to JSON. Read more about Global Data Files.

Data Template Engine
Object Key dataTemplateEngine
Default "liquid" (before 1.0)
Default false (1.0 and above)
Valid Options A valid template engine short name or false
Command Line Override None

Global JSON data files (not template/directory data files) can be optionally preprocessed with a template engine specified under the dataTemplateEngine configuration option.

Example Jump to heading

Filename .eleventy.js
module.exports = function(eleventyConfig) {
return {
"dataTemplateEngine": "njk"
}
};

For example, if your dataTemplateEngine is using njk or liquid you can do this in any *.json files in your _data folder:

Filename _data/myfile.json
{
"version": "{{ pkg.version }}"
}

package.json data is available here supplied by Eleventy in the pkg variable.