Is it possible to send more than two arguments with a .view response in HAPIJS

In my module.exports:

module.exports.getselectedtimeperiod = function getselectedtimeperiod (request, reply) {
  var from = request.query.from || Moment().subtract(5, 'day')
  var to = request.query.to || Moment.now()
  var fromDate = Moment(from).unix()
  var toDate = Moment(to).unix()
  var url = config.LOG_SKOLESKYSS_GET_APPLICATIONS + fromDate + '/' + toDate
  Wreck.get(url, wreckOptions, function (err, data, payload) {
    if (err) {
      reply(err)
    }   
    request.yar.set({'sokerdata': payload})
    reply.view('show-applicants', payload)
  })
}

I would like to send a “payload” and “viewOptions” to my views, which contains (the title for the tab) and other specific variables in the package.json file. is there any way to overcome this problem? Of course, getting errors when trying to do it like this:

reply.view('show-applicants', payload, viewOptions)
+4
source share
1 answer

If you want to send your opinions, I think you can pass the object instead.

reply.view('show-applicants', {
  payload: payload,
  viewOptions: viewOptions
});

Then, in your opinion, ex. handles, you can access variables with:

{{payload}} and {{viewOptions}}
<!-- or {{payload.someKey}} in case of access key in object -->
+1
source

Source: https://habr.com/ru/post/1648783/


All Articles