Skip to content
Advertisement

Return view in controller AdonisJS

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

Advertisement

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

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement