-
-
Notifications
You must be signed in to change notification settings - Fork 558
Description
I was trying to use data from the Data Cascade in a filter. I asked about it in this discussion: #2841 and @pdehaan extremely helpfully solved it.
The relevant docs I could find are here:
https://www.11ty.dev/docs/filters/#scoped-data-in-filters
which say:
A few Eleventy-specific data properties are available to filter callbacks.
this.pageAdded in v2.0.0this.eleventyAdded in v2.0.0module.exports = function(eleventyConfig) { // Make sure you’re not using an arrow function here: () => {} eleventyConfig.addFilter("myFilter", function() { // this.page // this.eleventy }); };
However, I think this documentation could be improved:
- There are more data properties available. For example, using Nunjucks,
this.ctxis available. Critically, it contains the entire Data Cascade (I think). Perhaps we could list all the properties that are available? - There are properties available before v2.0.0. Because both the properties listed are tagged as v2.0.0, I thought those were the only ones. Since I was on v1.0.0, I didn't think the arrow function distinction would affect me, but it does.
- The properties that are available depend on the filter. From @pdehaan, they're available at:
- Nunjucks:
this.ctx - Liquid:
this.context.environments - Eleventy: (must pass in manually)
- Nunjucks:
I think it's because I'm bad at JavaScript, but I find it very difficult to figure out what information I can access when I'm working inside filters or templating languages. Having documentation that lists out variables more exhaustively would help me out a lot. (I run into this genre of issue frequently working on my Eleventy + Nunjucks site.)
Many thanks for your consideration!