render method
Renders a template file with the given context.
The template file should be an HTML file with placeholders in the form
of {{ key }}
where key
is a key in the context
map.
The rendered template is returned as a string.
templatePath
: The path to the template file.context
: The map containing the context for the template.
Implementation
Future<String> render(
String templatePath, Map<String, dynamic> context) async {
String template = await File(templatePath).readAsString();
template = await _processInheritance(template, context);
template = _processLoops(template, context);
template = _processConditionals(template, context);
context.forEach((key, value) {
template = template.replaceAll('{{ $key }}', value.toString());
});
return template;
}