Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Aug 17, 2022
1 parent 927911e commit 953c583
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/docs/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ module.exports = function(eleventyConfig) {

// or, use a Universal filter (an alias for all of the above)
eleventyConfig.addFilter("makeUppercase", function(value) { … });

// New in 2.0.0-canary.15
eleventyConfig.addAsyncFilter("makeUppercase", async function(value) { … });
};
```

Expand Down Expand Up @@ -97,6 +100,33 @@ module.exports = function(eleventyConfig) {
};
```

### Asynchronous Universal Filters {% addedin "2.0.0-canary.15" %}

Eleventy has added a new universal filter API for asynchronous filters and extended the currently available `addFilter` method to be async-friendly. _Note that even though Handlebars is used for synchronous filters in `addFilter`, it is excluded from asynchronous filters because Handlebars is not async-friendly._

If you are not yet on Eleventy 2.0, you can still add asynchronous filters to each async-friendly template language individually: [Liquid `addLiquidFilter`](/docs/languages/liquid/#filters), [Nunjucks `addNunjucksAsyncFilter`](/docs/languages/nunjucks/#asynchronous-nunjucks-filters), and [JavaScript `addJavaScriptFunction`](/docs/languages/javascript/#asynchronous-javascript-template-functions).

{% codetitle ".eleventy.js" %}

```js
module.exports = function(eleventyConfig) {
// Async universal filters add to:
// * Liquid
// * Nunjucks
// * JavaScript

eleventyConfig.addFilter("myFilter", async function(value) {
// do some Async work
return value;
});

eleventyConfig.addAsyncFilter("myFilter", async function(value) {
// do some Async work
return value;
});
};
```

### Eleventy Provided Universal Filters

We also provide a few universal filters, built-in:
Expand Down
5 changes: 5 additions & 0 deletions src/docs/languages/liquid.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ Filters are used to transform or modify content. You can add Liquid specific fil

Read more about [LiquidJS Filter syntax](https://liquidjs.com/tutorials/register-filters-tags.html)

Note that Liquid supports asynchronous filters out of the box (without any additional code or API method changes).

```js
module.exports = function(eleventyConfig) {
// Liquid Filter
eleventyConfig.addLiquidFilter("myLiquidFilter", function(myVariable) { … });

// Async-friendly too
eleventyConfig.addLiquidFilter("myAsyncLiquidFilter", async function(myVariable) { … });

// Universal filters (Adds to Liquid, Nunjucks, and Handlebars)
eleventyConfig.addFilter("myFilter", function(myVariable) { … });
};
Expand Down

0 comments on commit 953c583

Please sign in to comment.