Key Features of the View System

1. Edge.js Templating Engine-based View System

This is an MVC pattern View system that integrates AdonisJS's Edge.js into NestJS.

Using Views in Controllers

// Using the @View() decorator in the controller
@Controller('admin/documents')
export class AdminDocumentsController {
  @Get()
  async index(@View() view: NestMvcView) {
    const documents = await this.documentsService.index();
    return view.render('pages/admin/documents/index', { documents });
  }
  
  @Get(':id/edit')
  async edit(@Param('id') id: number, @View() view: NestMvcView) {
    const document = await this.documentsService.getById(id);
    return view.render('pages/admin/documents/edit', { document });
  }
}

Accessing Views through the Request Object

// Accessing views through NestMvcReq (used with Flash messages)
@Post()
async create(@Req() req: NestMvcReq) {
  await this.createDocumentUseCase.execute(req.body?.document);
  req.flash.success('Operation successful');
  return req.view.render('pages/admin/documents/_success');
}