simple_mustache 2.1.0 copy "simple_mustache: ^2.1.0" to clipboard
simple_mustache: ^2.1.0 copied to clipboard

Dart implementation of a mustache subset for simple String templates with filters.

example/main.dart

import 'package:simple_mustache/simple_mustache.dart';

void main() {
  // Create a mustache converter
  final m = Mustache(
    map: <String, dynamic>{
      'name': 'David',
    },
  );

  // Convert a template
  final output = m.convert('Hello, my name is {{ name }}.');
  print(output);

  // Create a more complicated mustache converter
  final m1 = Mustache(
    map: <String, dynamic>{
      'events': <Map>[
        <String, dynamic>{
          'name': 'Event 1',
          'date': DateTime.fromMillisecondsSinceEpoch(-1893200147000),
        },
        <String, dynamic>{
          'name': 'Event 2',
          'date': DateTime.fromMillisecondsSinceEpoch(1893200147000),
        },
      ],
    },
    filters: {
      'dt': (dynamic d) => d is DateTime ? d.year : 'Invalid data',
    },
  );

  // Convert a template
  print(m1.convert(
      'List of events:\n{{# events }}  {{ name }}, year: {{ date | dt }}\n{{/ events }}'));
}
8
likes
160
pub points
84%
popularity

Publisher

verified publishernfet.net

Dart implementation of a mustache subset for simple String templates with filters.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

logging

More

Packages that depend on simple_mustache