-
-
Notifications
You must be signed in to change notification settings - Fork 491
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
Pass arguments from .njk
to _data
file with async functions
#471
Comments
I believe to get async behavior in Nunjucks (in this way) you want an async filter: https://www.11ty.io/docs/languages/nunjucks/#asynchronous-nunjucks-filters |
I will give it a go! Thanks @zachleat 💯 |
For anyone who comes across this issue in the future, this is how I solved it:
|
Why did you use Got? (I mean, axios is quite popular). Others brought fetch to node.js. |
I just like the API for |
Would be awesome if that would become a filter for eleventy published on npm. Would you like to create one? |
@Ryuno-Ki go for it, happy to review the code when you are done! |
@Ryuno-Ki nice work and you made it so quickly. I think it would be useful to decouple it though. So you can fetch a URL and return the data. The user can then change it up if they wanted to fetch GitHub stars or from another API. What do you think? The input would be something like |
Please fill a ticket in that GitHub repo of mine :-) |
For anyone wanders here... If you use a nunjucks asyncfilter inside a template and include that template inside a if condition like the following,
it won't render at all. You can use |
I am not sure if this is similar to #335 . I would like in the data file to take the
npm
package name from the markdown and use it to get data from npm:_data/livestats.js
page-project.njk
This currently returns
[object Promise]
but it would be awesome to await and return the result.The problem I am trying to get around is iterating through markdown to find frontmatter that contains
npm
. It would be great if I could pass thenpm
string to a function to fetch information.The text was updated successfully, but these errors were encountered: