Render basic HTML view ?



  • 3 Answer(s)

    We can have a plain HTML page:

    For views/index.jade

    include plain.html
    

    For views/plain.html

    <!DOCTYPE html>
    ...
    

    And then  app.js can still simply render jade:

    res.render(index)
    
    Answered on December 26, 2018.
    Add Comment

    The following works for to using express 3.0.0 and 3.1.0

    app.set('views', __dirname + '/views');
    app.engine('html', require('ejs').renderFile);
    

    To look the criticism below for alternative syntax and caveats for express 3.4+:

    app.set('view engine', 'ejs');
    

    And then you can try this one,

    app.get('/about', function (req, res)
    {
        res.render('about.html');
    });
    

    To you look for having your views in the views subfolder, and that you have installed the ejs node module. If not, run the following on a Node console:

    npm install ejs --save
    
    Answered on December 26, 2018.
    Add Comment

    Guide for Express.js

    To show filenames took the form Express.ENGINE, Where the  module is a engine that will be need For Ex: the view layout.ejs will tell the view system to require(‘ejs’), the module being loaded must export the method exports.render(str, options) to comply with Express, however app.register() can be used to map engines to file extensions, so  foo.html can be rendered by jade.

    You can make your idea to renderer.

    app.register('.html', require('jade'));
    
    Answered on December 26, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.