jinja 0.5.0
jinja: ^0.5.0 copied to clipboard
Jinja2 template engine for Dart. Variables, expressions, control structures and template inheritance.
jinja #
Jinja (3.x) server-side template engine port for Dart 2. Variables, expressions, control structures and template inheritance.
Version 0.5.0 introduces breaking changes #
Auto-escaping and related filters and tests have been removed due to the impossibility of extending String. Use the escape filter manually or escape values before passing them to the template.
For more information, see CHANGELOG.md.
Documentation #
It is mostly similar to Jinja templates documentation, differences provided below. work in progress.
Differences with Python version #
- The
defaultfilter compares values withnull; there is nobooleanparameter. - The
definedandundefinedtests compare values withnull. - The
mapfilter also compares values withnull. Useattributeanditemfilters forobject.attributeandobject[item]expressions. - If
Environment({getAttribute})is not passed, thegetItemmethod will be used. This allows you to use{{ map.key }}as an expression equivalent to{{ map['key'] }}. - Not yet supported:
- Slices and negative indexes
- Conditional and variable
extendsstatement variants - Choice, ignore missing and variable
includestatement variants
- work in progress
Dynamically invoked members #
[],+,-,*,/,~/,%operatorsobject.lengthgetterobject.callgetterFunction.apply(function, ...)
Example #
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.
Status: #
TODO: #
Template:generatestreamawaitsupport
- Template Inheritance
- Template Objects
- List of Control Structures
- Macros 🔥
- Call 🔥
- Import
- Loaders
- PackageLoader (VM)
- ...
- List of Global Functions
lipsumdictcyclerjoiner
- Extensions
- i18n
- Loop Controls
- Debug Statement
- Template compiler (builder)
- ...
Done: #
Note: item - unsupported
- Variables
- Filters
forceescapesafeunsafe
- Tests
escaped
- Comments
- Whitespace Control
- Escaping (only
escapefilter) - Line Statements
- Comments
- Blocks
- Template Inheritance
- Base Template
- Child Template
- Super Blocks
- Nesting extends
- Named Block End-Tags
- Block Nesting and Scope
- Required Blocks
HTML Escaping- List of Control Structures
- For
- If
- Filters
- Assignments
- Block Assignments
- Extends
- Blocks
- Include
- Import Context Behavior
- Include
- Expressions with filters and tests
- Literals
- Math
- Comparisons
- Logic
- Other Operators
- If Expression
- Dart Methods
- List of Global Functions
printrangelistnamespace
- Loaders
- FileSystemLoader
- MapLoader (DictLoader)
- Extensions
- Expression Statement
- With Statement
Autoescape Overrides
Support #
Post issues and feature requests on the GitHub issue tracker.