- Stable
2.0.1
- Beta
3.0.0-beta.1
- Canary
3.0.0-alpha.20
Toggle Menu
Eleventy
1.93s
Gatsby
29.05s
Preprocessors Pre-release only: v3.0.0-alpha.17
Contents
The Preprocessor Configuration API allows you to intercept and modify the content in template files (not Layouts) before they’re processed and rendered by Eleventy.
Example: Drafts
Here’s an example that uses the Preprocessor API to implement a Drafts workflow:
export default function(eleventyConfig) {
eleventyConfig.addProcessor("drafts", "njk,md,liquid", (data, content) => {
// If `draft` is truthy in the template’s Data Cascade, ignore the file.
if(data.draft) {
return false;
}
// You can also modify the raw input of the template here too, be careful!
return `${content}<!-- Template file: {{ page.inputPath }} -->`;
// If you return nothing or `undefined`, no changes will be made to this template.
});
};
- The first argument is an arbitrary
name
(String
) used for error messaging. - The second argument can be:
- a
String
of comma separated file extensions - an
Array<String>
of file extensions
- a
- Returning
false
will ignores the template in the same way as usingeleventyConfig.ignores
or.eleventyignore
- Returning nothing or
undefined
has no effect (unlike Transforms)
Originally GitHub Issue #188.