Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easy way to access global data in a page #1535

Closed
Zearin opened this issue Nov 27, 2020 · 2 comments
Closed

Easy way to access global data in a page #1535

Zearin opened this issue Nov 27, 2020 · 2 comments

Comments

@Zearin
Copy link
Contributor

Zearin commented Nov 27, 2020

Is your feature request related to a problem? Please describe.

This feature request was born out of #1526.

My original post:

I just want to print out all the data to look at how it’s structured.

I basically want to do the equivalent of a console.dir(…) or console.inspect(…), but print the data within a <pre>…</pre> element.

Can I do this?

How?

(To be clear, I am referring to global data.)

An obvious solution was nowhere to be found. But thanks to some help from @pdehaan and @Ryuno-Ki, I was about to figure out that a page can access all global data in 2 steps.

  1. Create a debug filter in Eleventy’s config (@pdehaan’s example is here)
  2. Use the debug filter like this: {{ collections.all[0].template.templateData.globalData | debug }}

This works…but it was tedious to pull off. And I would not have figured it out if it weren’t for the help I received in #1526.

Being able to “just look at” data is an important part of discovery, learning, and adoption of new tools. For example, now that I know I can do this, I plan to stick with Eleventy a little longer to see what I can do.

Describe the solution you’d like

I guess I would just like an easy-access variable available to do this.

  • perhaps called globalData
  • perhaps defaulting to globalData, but allowing the user to configure a different name
  • perhaps something else?

Describe alternatives you've considered

N/A

----

EDIT: Put my writing under the correct questions 👅
EDIT: Clarify that I mean global data, rather than front matter

@Zearin
Copy link
Contributor Author

Zearin commented Nov 28, 2020

@zachleat Could this be part of the Eleventy 1.0 milestone?

@zachleat
Copy link
Member

zachleat commented Aug 4, 2021

Howdy! I think the best way forward is over at #1919, can you upvote and subscribe over there?

@zachleat zachleat closed this as completed Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants