javascript - Use HTML with dynamic fields to render response in Express Node JS framework -
i able route simple html file without using jade replacing code under routes folder index.js file 1 below:
router.get('/', function(req, res){ res.sendfile('index.html', { root: path.join(__dirname, '../views') });
});
html code:
<html> <head></head> <body> <p>hi!</p> </body> </html>
how can replace "hi!" static string similar #{myvalue} tag of jade? example add in p tag current datetime. file maybe not .html static, .js or anything. looking .php files do. new express , node.js , asking know if possible not use jade style html style views?
you can use html in jade
index.jade
:
<html> <head></head> <body> <p>#{myvalue}</p> </body> </html>
just render jade
res.render('index.jade');
*caveat*: indentation throw errors. because of obvious reason indentation interpreted jade tags' scopes.
so this won't work:
<html> <head></head> <body> <p>#{myvalue}</p> </body> </html>
a solution use parent tag trailing dot operator, inside of treated plain text (i.e. html if you're using tags). this work:
html. <head></head> <body> <p>#{myvalue}</p> </body>
Comments
Post a Comment