Return view in controller AdonisJS

Tags: ,



How can I return a view and display it through the controller in AdonisJs

'use strict'

class PostController {

  index(){
    return view.render('welcome')
  }

}

module.exports = PostController

report this error:

ReferenceError
view is not defined

Answer

You can use response.send(view.render('<your_view>'))

Something like:

...
index({ response, view }){ // Get objects from HTTP Context
  return response.send(view.render('welcome'))
}

HTTP Context documentation

Official forum answer



Source: stackoverflow