Jinja (3.x) server-side template engine port for Dart 2. Variables, expressions, control structures and template inheritance.
FilterArgumentError
error class removed*args
and **kwargs
arguments support removedString
.
Use the escape
filter manually or escape values before passing them to the template.For more information, see CHANGELOG.md
.
It is mostly similar to Jinja templates documentation, differences provided below.
work in progress.
default
filter compares values with null
.defined
and undefined
tests compare values with null
.map
filter also compares values with null
.
Use attribute
and item
filters for object.attribute
and object[item]
expressions.Environment({getAttribute})
is not passed, the getItem
method will be used.
This allows you to use {{ map.key }}
as an expression equivalent to {{ map['key'] }}
.[]
, +
, -
, *
, /
, ~/
, %
operatorsobject.length
getterobject.call
getterFunction.apply(function, ...)
import 'package:jinja/jinja.dart';
// ...
var environment = Environment(blockStart: '...', blockEnd: '...');
var template = environment.fromString('...source...');
print(template.render({'key': value}));
// or write directly to StringSink (IOSink, HttpResponse, ...)
template.renderTo(stringSink, {'key': value});
See also examples with conduit and reflectable.
Template
class:
generate
methodstream
method{{ super.super() }}
block
statements and expressions
{% extends 'base.html' %}
{% set title = 'Index' %}
{% macro header() %}
<h1>{{ title }}</h1>
{% endmacro %} ```
{% block body %}
{{ header() }}
{% endblock %}
!.
/?.
lipsum
cycler
joiner
Note: item - not supported
forceescape
safe
unsafe
escaped
escape
filter)"Hello World"
42
/ 123_456
42.23
/ 42.1e2
/ 123_456.789
['list', 'of', 'objects']
('tuple', 'of', 'values')
{'dict': 'of', 'key': 'and', 'value': 'pairs'}
true
/ false
null
+
-
/
//
%
*
**
==
!=
>
>=
<
<=
and
or
not
(expr)
in
is
|
~
()
.
/[]
{{ list.last if list }}
{{ user.name if user else 'Guest' }}
{{ string.toUpperCase() }}
{{ list.add(item) }}
dict
print
range
list
namespace
FileSystemLoader
MapLoader
(DictLoader
)Contributions are welcome! Please open an issue or pull request on GitHub. Look at the ToDo list and comments in the code for ideas on what to work on. There are no strict rules, but please try to follow the existing code style.
As non-native English speaker and learner, I will be grateful for any corrections in the documentation and code comments.
Post issues and feature requests on the GitHub issue tracker.