Express: How to render from string?

Created on 6 Mar 2017  路  3Comments  路  Source: expressjs/express

Hello.

How to render from string?

index.js

res.render('index', {"hello": "world"});

index.ejs

<%- hello %>

We need so:

var hello = '<%- hello %>';
res.render(hello, {"hello": "world"});

It's possible?

4.x question

Most helpful comment

Depending on the case, typically you would just use the engine directly. For example:

var hello = '<%- hello %>';
res.send(ejs.render(hello, {"hello": "world"}));

All 3 comments

Depending on the case, typically you would just use the engine directly. For example:

var hello = '<%- hello %>';
res.send(ejs.render(hello, {"hello": "world"}));

@dougwilson This is exactly what I need. Thank you.

No problem :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Domiii picture Domiii  路  3Comments

dmaks9 picture dmaks9  路  3Comments

HafidAbnaou picture HafidAbnaou  路  3Comments

afanasy picture afanasy  路  3Comments

zackarychapple picture zackarychapple  路  3Comments