A tiny template renderer walks a {key: value} map and swaps each <<key>> placeholder in the template with the matching value. replaceAll does the heavy lifting; the loop just rebinds result once per entry.

Program

Play the program to render a small template with two placeholders.

string_template_lite.dart
Replay: real traced execution (multi-file project)
void main() {
  var template = '<<name>> has <<count>> tasks';
  var values = {'name': 'Ada', 'count': '3'};
  var result = template;
  for (var entry in values.entries) {
    result = result.replaceAll('<<${entry.key}>>', entry.value);
  }
  print(result);
}
  1. template ← <<name>> has <<count>> tasks

    1void main() {2  var template = '<<name>> has <<count>> tasks';3  var values = {'name': 'Ada', 'count': '3'};
    values this step<<name>> has <<count>> taskstemplate
  2. values ← 2 keys

    2var template = '<<name>> has <<count>> tasks';3var values = {'name': 'Ada', 'count': '3'};4var result = template;
    values this step2 keysvalues
  3. result ← <<name>> has <<count>> tasks

    3var values = {'name': 'Ada', 'count': '3'};4var result = template;5for (var entry in values.entries) {
    values this step<<name>> has <<count>> tasksresult
  4. loop ← replace placeholders

    4var result = template;5for (var entry in values.entries) {6  result = result.replaceAll('<<${entry.key}>>', entry.value);
    values this stepreplace placeholdersloop
  5. result ← Ada has 3 tasks

    5for (var entry in values.entries) {6  result = result.replaceAll('<<${entry.key}>>', entry.value);7}
    values this stepAda has 3 tasksresult
  6. print(result);

    7  }8  print(result);9}
    outputAda has 3 tasks
    values this stepAda has 3 tasksresult
placeholders Wrap each key in `<<...>>` so the template reads cleanly next to surrounding text.
replaceAll `result.replaceAll('<<name>>', 'Ada')` swaps every occurrence; safe when a placeholder repeats.
rebind `result = result.replaceAll(...)` rebinds the same name each iteration since Dart strings are immutable.