Server Side Rendered Views
Just like
res.render
in Express, Angel'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/dukefirehawk/angel/tree/master/packages/mustache
Angel support for Jinja2 can be found here: https://github.com/dukefirehawk/angel/tree/master/packages/angel_jinja
app.get('/view', (req, res) async => await res.render('hello', {'locals': ['foo', 'bar']});
Angel declares the following typedef:
/// A function that asynchronously generates a view from the given path and data.
typedef Future<String> ViewGenerator(String path, [Map data]);
A templating plug-in can assign one of these to
app.viewGenerator
to set itself up:import 'dart:io';
import 'package:angel3_framework/angel3_framework.dart';
Future<void> plugin(Angel app) async {
app.viewGenerator = (String path, [Map data]) async {
return "Requested view $path with locals: $data";
};
}
void main() async {
var app = Angel();
await app.configure(plugin);
await app.startServer();
}
Last modified 8mo ago