Use of presenters in Adonis 4

Hello,

Please, can someone show me an example of using presenters in Adonis 4.

How the view in controllers can locate the presenters’ folder ?

Thank you…

Create presenters folder inside resources folder.
A basic presenter looks like this:

'use strict'

const { BasePresenter } = require('edge.js')

class Index extends BasePresenter {

  get posts () {
    const posts = this.$data.posts
    // do something with the posts
    return posts
  }

}

module.exports = Index

Then you can chain presenter before your view.render('index'), kinda like this: view.presenter('index').render('index')

If you want to know more take a look at the video here:
http://edge.adonisjs.com/docs/presenters

2 Likes

Thank you @keeross !

Estuve realizando el ejemplo que me compartiste de crear la carpeta de presenters en la carpeta de los recursos pero no me funciono.

me mandaba el errror que no existe la ruta.