Where to access and store EJS Helpers - SailsJS

前端 未结 3 727
攒了一身酷
攒了一身酷 2021-01-13 08:44

Well,

SailJS\'s default templateing engine is EJS (Embedded Javascript)

But I cannot seem to find the place where we can create ou

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-13 09:28

    You should create file in ./config with name anyname.js and write some EJS helper like these code:

    var moment = require('moment');
    var ejs = require('ejs');
    
    ejs.filters.fromNow = function(date){
      return moment(date).fromNow()
    }
    ejs.filters.formatDate = function(date){
      return moment(date).format('MMM Do YYYY');
    }
    ejs.open = '';
    

    Then in layout, view, it should be call

    
    

    Hope that help!

    Update

    For some reasons, you guys have to install module sails locally to make sense. So just paste to your console:

    npm i sails
    

    regards,

    Anh Nguyen

提交回复
热议问题