View extension

Extension on HttpRequest to render HTML views.

This extension centralizes template rendering, CSRF token setup, response header configuration, and request/session view data composition.

Example:

return request.view('dashboard.index', {
  'title': 'Dashboard',
  'posts': posts,
});
on

Methods

view(String template, [ViewData? data]) Future<HttpResponse>

Available on HttpRequest, provided by the View extension

Renders an HTML template and writes it to the response.