Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change sails.js EJS views to use .html extensions instead of .ejs extensions?

Is it possible to configure sails.js apps to use .html extentions rather than .ejs (but still use the ejs view engine)?

sails new app creates ./views/home/index.ejs and ./views/layout.ejs.

I'd like to change the extensions to .html but keep everything else working the same way.

ie: I would now have ./views/home/index.html and ./views/layout.html, and the home page would still be injected into the layout page, as per normal.

How can I configure this please?

like image 371
Steve Lorimer Avatar asked Jan 09 '14 06:01

Steve Lorimer


2 Answers

In your config/views.js:

engine: {
  ext: 'html',
  fn: require('ejs').renderFile
},

Seems though that the future support for this feature is not guaranteed, since they removed this from docs, so use with caution.

like image 80
bredikhin Avatar answered Oct 17 '22 05:10

bredikhin


Another approach

Sails provides EJS templating by default.To override this and to use .html files , here is a simple solution. In your Sails App , go to config/routes.js. You will see following code there

module.exports.routes = {

 /***************************************************************************
 *                                                                          *
 * Make the view located at `views/homepage.ejs` (or `views/homepage.jade`, *
 * etc. depending on your default view engine) your home page.              *
 *                                                                          *
 * (Alternatively, remove this and add an `index.html` file in your         *
 * `assets` directory)                                                      *
 *                                                                          *
 ***************************************************************************/

 '/': {
   view: 'homepage'
 }

 /***************************************************************************
 *                                                                          *
 * Custom routes here...                                                    *
 *                                                                          *
 *  If a request to a URL doesn't match any of the custom routes above, it  *
 * is matched against Sails route blueprints. See `config/blueprints.js`    *
 * for configuration options and examples.                                  *
 *                                                                          *
 ***************************************************************************/

};

Remove the route to '/' as shown below . Keep it blank

New routes.js will look like

module.exports.routes = {

   //Remove '/' :)

};

Okay !!! now it’s done you can use your HTML files in Sails app . Put your index.html in assets folder . Sails will now load views from here :)

like image 41
Pranav Raj S Avatar answered Oct 17 '22 06:10

Pranav Raj S