You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Documentation/helper functions for dumping collections state info #266
I've been experimenting with taking some of the templating and state management that 11ty provides and moving it into a service worker.
As part of that process, the service worker needs access to data (i.e. HTML-formatted content) and metadata (e.g. titles, dates, tags, other post-specific state info, along with global config that lives under _data/) as well as the underlying templates used to render the final HTML.
It's possible to collect a good deal of this required info at build time and format it so that it could be cached by the service worker and used later on. (Here's an example of how I'm doing that, and @zachleat offered some suggestions on Twitter for improving that process for post-specific [meta]data.)
One of the thing I'm not sure how to do is to get at 11ty's internal data about collections, which would need to be dumped at build time, and read by the service worker at runtime, in order to have the service worker render index.html-style templates, or deal with pagination. It would be great to see either documentation as to how to get at that data, or for a new helper function to be created to make it easy to dump out all of the internal state that might be useful for this purpose.
(In the course of researching this issue I found #130, which is tangentially related.)
Reacted by Benedikt Gregor, kaizenseed and TechAurelianMisc2
Just as a quick note (I’ll leave more feedback here later) the last issue you mentioned is almost certainly #263 and will be fixed in the next version.
I’d recommend re-checking this after 0.6.0 is released and then we can decide whether to this needs additional work and needs to go into the enhancement queue or not.
If the following example is still broken in 0.6.0 I’d consider that a bug:
Since I stumbled upon the same issue, I went with javascript-stringify solution mentioned above. I am debugging for now the (circular) objects in the console with {{ collections.nav | console }}.
Reacted by J. B. Rainsberger, Andressa, Corentin Le Fur, dwkns, Carlos Filoteo, Anatoliy Skichko, Kunal SIngh, Aram Zucker-Scharff, Ted Whitehead, Leif Niemczik and 2 more
Activity
jeffposnick commentedon Oct 3, 2018
FWIW, I've naively tried
which leads to
zachleat commentedon Oct 7, 2018
Just as a quick note (I’ll leave more feedback here later) the last issue you mentioned is almost certainly #263 and will be fixed in the next version.
zachleat commentedon Nov 17, 2018
I’d recommend re-checking this after 0.6.0 is released and then we can decide whether to this needs additional work and needs to go into the enhancement queue or not.
If the following example is still broken in 0.6.0 I’d consider that a bug:
jeffposnick commentedon Nov 19, 2018
Sounds good—could you ping this issue when
0.6.0is released so that I don't miss it? I'm eager to try things out.jeffposnick commentedon Nov 26, 2018
I've updated to
0.6.0and am still seeing the samewhen attempting to dump the
collections.postdata.wesruv commentedon Dec 21, 2018
I'm getting the same as @jeffposnick
zachleat commentedon Dec 21, 2018
I don’t think using JSON.stringify is gonna get us there, sorry y’all.
Can you try https://www.npmjs.com/package/javascript-stringify instead and see if it will work? I do use it for JSTL file processing so I know that it can convert the object.
You can make your own filter to do this, and use it just like you would
dump. https://www.11ty.io/docs/filters/jeffposnick commentedon Dec 28, 2018
When going down the custom filter route, I think I could get what I want just by explicitly listing the fields I want dumped:
zachleat commentedon Jan 8, 2019
Ah, that’s great @jeffposnick. Is that enough to consider this resolved?
jeffposnick commentedon Jan 8, 2019
Yeah, I think this can be closed—that might end up being a useful snippet to include in the docs, though.
zachleat commentedon Jan 8, 2019
fabarea commentedon Jun 25, 2019
Since I stumbled upon the same issue, I went with javascript-stringify solution mentioned above. I am debugging for now the (circular) objects in the console with
{{ collections.nav | console }}.The implementation is very raw but this might help.
Ryuno-Ki commentedon Jun 25, 2019
Thank you!
stephane-klein commentedon Oct 25, 2020
With this solution I have always circular reference error.
Now, I use this with success in my
.eleventy.js:dwkns commentedon May 14, 2021
Adding to @stephane-klein answer if you use:
And then:
You get nicely formatted output.
murtuzaalisurti commentedon Apr 6, 2022
great!
zachleat commentedon Nov 6, 2025
Notably, the
logfilter was shipped with v0.11.0 #929Docs: https://www.11ty.dev/docs/filters/log/
Marginally related to #3744