jinja 0.6.0 copy "jinja: ^0.6.0" to clipboard
jinja: ^0.6.0 copied to clipboard

Jinja2 template engine for Dart. Variables, expressions, control structures and template inheritance.

example/example.dart

import 'dart:io';

import 'package:jinja/jinja.dart';
import 'package:jinja/loaders.dart';

void main() {
  var templates = Platform.script.resolve('templates').toFilePath();

  var env = Environment(
    globals: <String, Object?>{
      'now': () {
        var dt = DateTime.now().toLocal();
        var hour = dt.hour.toString().padLeft(2, '0');
        var minute = dt.minute.toString().padLeft(2, '0');
        return '$hour:$minute';
      },
    },
    autoReload: true,
    loader: FileSystemLoader(paths: <String>[templates]),
    leftStripBlocks: true,
    trimBlocks: true,
  );

  print(env.getTemplate('users.html').render({
    'users': [
      {'fullname': 'John Doe', 'email': 'johndoe@dev.py'},
      {'fullname': 'Jane Doe', 'email': 'janedoe@dev.py'},
    ]
  }));
}

// ignore_for_file: avoid_print
36
likes
160
pub points
89%
popularity

Publisher

unverified uploader

Jinja2 template engine for Dart. Variables, expressions, control structures and template inheritance.

Repository (GitHub)
View/report issues

Documentation

API reference

Funding

Consider supporting this project:

www.buymeacoffee.com

License

MIT (license)

Dependencies

html_unescape, meta, path, string_scanner, textwrap

More

Packages that depend on jinja