Thursday, 11 May 2017

How to use ejs template which is stored in variable but not a file?

Originally, I have an ejs template like

<!DOCTYPE html><html>other complex and long ejs and html codes here</html>.

After escape that template by using an online tool, I store that value in a field in MongoDB. In NodeJS, I access that field and retrieve its value. I unescape that value, creating a variable (let call 'mytemplate') to store it. My question is how I can have actual template with variable mytemplate. I searched ejs document and tried with some function like ejs.compile(mytemplate) but it didn't work. I also have some data to pass to that template once it is created. Last but not least, I want to send final template (within the data) to browser (similar to function res.render(template,data). How can I achieve that? Thank you so much!



via sonle

No comments:

Post a Comment