twig_dart 3.0.0 copy "twig_dart: ^3.0.0" to clipboard
twig_dart: ^3.0.0 copied to clipboard

A simple server-side HTML templating engine for Dart. Comparable to Blade or Liquid.

example/main.dart

import 'dart:io';
import 'package:charcode/charcode.dart';
import 'package:essential_code_buffer/essential_code_buffer.dart';
import 'package:essential_symbol_table/essential_symbol_table.dart';

import 'package:twig_dart/twig_dart.dart' as twig_dart;

main() {
  while (true) {
    var buf = StringBuffer();
    int ch;
    print('Enter lines of twig_dart text, terminated by CTRL^D.');
    print('All environment variables are injected into the template scope.');

    while ((ch = stdin.readByteSync()) != $eot && ch != -1) {
      buf.writeCharCode(ch);
    }

    var document = twig_dart.parseDocument(
      buf.toString(),
      sourceUrl: 'stdin',
      onError: stderr.writeln,
    );

    if (document == null) {
      stderr.writeln('Could not parse the given text.');
    } else {
      var output = CodeBuffer();
      const twig_dart.Renderer().render(
        document,
        output,
        SymbolTable(values: Platform.environment),
        strictResolution: false,
      );
      print('GENERATED HTML:\n$output');
    }
  }
}
3
likes
130
pub points
22%
popularity

Publisher

verified publishergalileodart.com

A simple server-side HTML templating engine for Dart. Comparable to Blade or Liquid.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

args, charcode, collection, essential_code_buffer, essential_symbol_table, matcher, source_span, string_scanner

More

Packages that depend on twig_dart