platform/packages/jinja
2023-05-20 15:37:23 +00:00
..
example Published Jinja 2021-06-26 18:34:23 +08:00
lib Update angel3_jinja.dart 2021-12-02 14:49:18 +08:00
.gitignore Add 'packages/jinja/' from commit '2a5abb684b7b68f0da4775e9ceaa22cb295d58da' 2020-02-15 18:22:09 -05:00
analysis_options.yaml Publish Jinja 2021-12-03 13:30:50 +08:00
AUTHORS.md Merged from sdk-2.12.x_nnbd 2021-06-20 20:37:20 +08:00
CHANGELOG.md Updated Change Log 2022-08-16 19:19:04 +08:00
LICENSE Publish Jinja 2021-12-03 13:30:50 +08:00
melos_angel3_jinja.iml Added melos 2022-03-19 09:37:28 +08:00
pubspec.yaml Updated to Dart 3 2023-05-20 15:37:23 +00:00
README.md Publish Jinja 2021-12-03 13:30:50 +08:00

Jinja View Template for Angel3

Pub Version (including pre-releases) Null Safety Gitter License

A service that renders Jinja2 view template into HTML for Angel3 framework. Ported from Python to Dart.

Example

import 'dart:io';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/http.dart';
import 'package:angel_jinja/angel_jinja.dart';
import 'package:path/path.dart' as p;

void main() async {
  var app = Angel();
  var http = AngelHttp(app);
  var viewsDir = p.join(
    p.dirname(
      p.fromUri(Platform.script),
    ),
    'views',
  );

  // Enable Jinja2 views
  await app.configure(jinja(path: viewsDir));

  // Add routes.
  // See: https://github.com/ykmnkmi/jinja.dart/blob/master/example/bin/server.dart

  app
    ..get('/', (req, res) => res.render('index.html'))
    ..get('/hello', (req, res) => res.render('hello.html', {'name': 'user'}))
    ..get('/hello/:name', (req, res) => res.render('hello.html', req.params));

  app.fallback((req, res) {
    res
      ..statusCode = 404
      ..write('404 Not Found :(');
  });

  // Start the server
  await http.startServer('127.0.0.1', 3000);
  print('Listening at ${http.uri}');
}