ejs icon indicating copy to clipboard operation
ejs copied to clipboard

including external html files

Open andrewtennison opened this issue 12 years ago • 3 comments

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?

andrewtennison avatar Jan 29 '13 14:01 andrewtennison

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

seandunaway avatar Jan 29 '13 17:01 seandunaway

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.

ForbesLindesay avatar Jan 29 '13 18:01 ForbesLindesay

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.

straub avatar Sep 11 '14 13:09 straub