A Dart package with support for a simple template language and engine that's built to be familiar to Dart developers.
To use package:silhouette and access its keyword information,
first add it as a dependency in your pubspec.yaml file:
dart pub add silhouetteThe package provides a singular built-in library:
-
package:silhouette/silhouette.dartPrimarily provides access to the
TemplateEngineandCompiledTemplatetypes to compile and render Silhouette templates, as well as the various types used to soundly represent data within templates.
By convention, Silhouette templates use the .sil file extension.
For example: template.sil, email.sil, layout.sil.
import 'package:silhouette/silhouette.dart';
void main() async {
final engine = TemplateEngine();
final template = engine.compile(
'Hello {{ name }}! You have {{ count }} messages.',
);
final result = await template.render(
{'name': 'Dash', 'count': 3}.toSilhouetteObject,
);
print(result);
}Hello {{ name }}!
Hello {{ user.name }}!
The first item is {{ items[0] }}.
The item at row {{ row }}, column {{ col }} is {{ matrix[row][col] }}.
WHY ARE YOU SHOUTING {{ name.toUpperCase() }}?
I'm searching for "{{ rawText.trim().toLowerCase() }}".
{{ "Hello World" }}
{{ 42 }}
{{ 3.14159 }}
{{ true }}
{{ null }}
This text is squished between two colons: {{- text -}} :'