template_engine 2.0.1
template_engine: ^2.0.1 copied to clipboard
A Dart package to parse and render templates, using (nested) variables and custom tags.

The TemplateEngine can:
- Parse the Template text into a parser tree
- Render the parser tree to an output such as:
Features #
Template code blocks support:
- Statements, like
- comments
- variable assignments
- if, then, else
- loops
- etc...
- Expressions that can contain (combinations of):
- Data types
- Constants
- Variables
- Operators
- Methods
- Functions
e.g. functions to import:
- Pure files (to be imported as is)
- Template files (to be parsed and rendered)
- XML files (to be used as a data source)
- JSON files (to be used as a data source)
- YAML files (to be used as a data source)
- All of the above can be customized by replacing or adding your own grammar.
Getting Started #
To get started:
- Read the wiki documentation
- See the examples
- Install the template_engine package in your project
- Start coding
Usage #
A typical way to use the template_engine:
test/src/template_engine_template_example_test.dart
import 'package:shouldly/shouldly.dart';
import 'package:template_engine/template_engine.dart';
import 'package:test/test.dart';
Future<void> main() async {
test('example should work', () async {
var engine = TemplateEngine();
var parseResult = await engine.parseText('Hello {{name}}.');
var renderResult = await engine.render(
parseResult,
variables: {'name': 'world'},
);
renderResult.text.should.be('Hello world.');
});
}
For more see: Examples
Documentation #
For more information read the template_engine wiki