Skip to content
pubscout

mustache_template

2.0.6, released 2 months ago by flutter.dev

A Dart library that parses and renders Mustache templates.

WASM-readyRock solid
$ flutter pub add mustache_template
Source repository

What it does

It parses Mustache template strings into Template objects and can render them with provided data maps. Supports strict and lenient modes, partials, lambdas, and HTML escaping control.

AI-written summary of version 2.0.6, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need server‑side or client‑side text generation using the Mustache syntax.
  • You want a pure‑Dart solution without external dependencies.

Skip it when

  • You require a full UI widget library or state‑management solution.
  • You need a template engine with built‑in HTML sanitization beyond simple escaping.

Strengths

  • Zero external dependencies and pure Dart implementation.
  • Supports Mustache spec, partials, lambdas, and both strict and lenient modes.

Weaknesses

  • Only handles text templating; no integration with UI frameworks.
  • Limited to Mustache features; no advanced templating extensions.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
0
const source = '''
{{# names }}
  <div>{{ lastname }}, {{ firstname }}</div>
{{/ names }}
{{^ names }}
  <div>No names.</div>
{{/ names }}
{{! I am a comment. }}
''';
final template = Template(source, name: 'example');
final output = template.renderString({
  'names': [
    {'firstname': 'Greg', 'lastname': 'Lowe'},
    {'firstname': 'Bob', 'lastname': 'Johnson'},
  ],
});

Alternatives

Packages that do the same job and could replace mustache_template.

Works with

Packages commonly used together with mustache_template: ones it builds on, ones built on it, and its own family.