ejs
ejs copied to clipboard
including external html files
I would like to be able to include an external html file. Due to architectural issues this is hosted on a cdn as an html file. This is not ejs and does not need passing, just including as an html string in the page.
<%-include('http://filepath/html') %>
Is this possible? If not I assume I could fork ejs to add something like
<%-includeHTML('http://filepath/html') %>
which could be cached on first request and I assume using something like http.get to get the html?
at your application start or at intervals you could fetch the file and save to a local variable that you expose to your templates.
http://nodejs.org/api/http.html#http_http_get_options_callback http://expressjs.com/api.html#app.locals http://expressjs.com/api.html#res.render
The problem here is that at present node.js does not support a synchronous http request (I wish it would) so you have to cache it before you can include it since EJS is synchronous. You could do something along these lines in QEJS (or I think dust) because that supports async operation.
Leaving this note for others who encounter this limitation:
straub/promised-ejs supports async rendering via the cujojs/when promise library, so could support an async includeHTML(...) function. While I'm just promised-ejs myself at the moment, I'd love to have more eyes on it.