Use Asynchronous functions in EJS templates?
See original GitHub issueHow to handle asynchronous function calls in the template?
I want to fetch some data (e.g. from GitHub API) and render them in the template.
Is it possible to do something like this?
<%
fetchData(..., function (err, data) { %>
<%- err ? "Error" : data.title %>
<% }); %>
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
ejs async true with node Express
For people who are still trying to figure out how to implement async ejs templates, I am listing my complete solution below:.
Read more >EJS -- Embedded JavaScript templates
async When true , EJS will use an async function for rendering. (Depends on async/await support in the JS runtime. Tags. <% 'Scriptlet'...
Read more >async-ejs
ejs with the ability to add asynchronous functions. ... Start using async-ejs in your project by running `npm i ... Template stuff here....
Read more >How to use the ejs.renderFileAsync function in ejs
To help you get started, we've selected a few ejs examples, based on popular ways it is used in public projects. ; FirstLegoLeague...
Read more >ejs.render JavaScript and Node.js code examples
Best JavaScript code snippets using ejs.render(Showing top 15 results out of 315) ... async function buildReadmeContent(context) { const template = await ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think in almost all cases, you should do any asynchronous stuff before you render your EJS string.
Something similar to this:
@TimothyGu @RyanZim To have an
ejs
like syntax but with async support, what should I do? Is it possible to build it on top ofejs
or should I parse everything from scratch again, like inajs
?