render method

  1. @override
Future<void> render(
  1. Response response
)
override

Renders the HTML content and writes it to the response.

This method sets the content type of the response to 'text/html; charset=utf-8'. It then attempts to render the content using the specified template and data. If an error occurs during rendering, it sets the response status code to 500 (Internal Server Error) and writes an error message to the response.

The response parameter is the response object where the rendered content will be written.

Implementation

@override
Future<void> render(Response response) async {
  writeContentType(response);
  try {
    if (content != null) {
      String contentTemplate = await engine.render(content!, data);
      response.write(contentTemplate);
    } else if (templateName != null) {
      String contentFile = await engine.renderFile(templateName!, data);
      response.write(contentFile);
    } else {
      response.statusCode = HttpStatus.notFound;
      response.write('');
    }
  } catch (e) {
    response.statusCode = HttpStatus.internalServerError;
    response.write('Error rendering template: $e');
  }
}