> For the complete documentation index, see [llms.txt](https://angel3-docs.dukefirehawk.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://angel3-docs.dukefirehawk.com/templates-and-views/rendering-views.md).

# Server Side Rendered Views

* [Rendering Views](#rendering-views)
  * [Example](#example)
  * [`ViewGenerator` typedef](#viewgenerator)

## Rendering Views

Just like `res.render` in Express, Angel3's `ResponseContext` exposes a `Future` called `render`. This invokes whichever function is assigned to your server's `viewGenerator`.

There is a Mustache templating plug-in for Angel available: <https://github.com/dart-backend/angel/tree/master/packages/mustache>

There is also [Jael](https://github.com/dart-backend/angel/tree/master/packages/jael/jael), one of the few actively-developed HTML templating engines for Dart.

Angel support for Jael is provided through [`package:angel3_jael`](https://github.com/dart-backend/angel/tree/master/packages/jael/angel_jael).

Another is Jinja2, which was recently ported by to Dart by [Olzhas Suleimen](https://github.com/ykmnkmi/jinja.dart).

Angel support for Jinja2 can be found here: <https://github.com/dart-backend/angel/tree/master/packages/jinja>

### Example

```dart
app.get('/view', (req, res) => res.render('hello', {'locals': ['foo', 'bar']}));
```

With Jael, for example:

```dart
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_jael/angel3_jael.dart';
import 'package:file/local.dart';

Future<void> configureServer(Angel app) async {
  var fileSystem = const LocalFileSystem();
  await app.configure(jael(fileSystem.directory('views')));
}
```

### ViewGenerator

Angel3 declares the following typedef:

```dart
/// A function that asynchronously generates a view from the given path and data.
typedef ViewGenerator = FutureOr<String> Function(String path, [Map<String, dynamic>? data]);
```

A templating plug-in can assign one of these to `app.viewGenerator` to set itself up:

```dart
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_framework/http.dart';

Future<void> plugin(Angel app) async {
  app.viewGenerator = (String path, [Map<String, dynamic>? data]) async {
    return 'Requested view $path with locals: $data';
  };
}

void main() async {
  var app = Angel();
  await app.configure(plugin);
  await AngelHttp(app).startServer('localhost', 3000);
}
```
