Skip to main content

jtl 2.0.0 copy "jtl: ^2.0.0" to clipboard
jtl: ^2.0.0 copied to clipboard

Jetleaf Template Language — a lightweight, high-performance template engine for generating HTML, text, and dynamic content.

example/lib/main.dart

// ignore_for_file: avoid_print

import 'package:jetleaf_core/lang.dart';
import 'package:jtl/jtl.dart';

void main() {
  print('========================================================');
  print('  🍃 JTL (Jetleaf Template Language) 2.0.0 Showcase');
  print('========================================================\n');

  final jtl = JtlFactory();

  // 1. Simple Variable Interpolation with HTML escaping
  print('[1] Simple Variable Interpolation:');
  const templateHtml = '''
<!DOCTYPE html>
<html>
<head><title>{{title}}</title></head>
<body>
  <h1>Welcome, {{user.name}}!</h1>
  <p>Email: {{user.email}}</p>
  <p>Escaped Content: {{unsafeHtml}}</p>
</body>
</html>''';

  final template = JtlTemplate(
    'views/welcome.html',
    {
      'title': 'JTL Showcase',
      'user': {
        'name': 'Alice Johnson',
        'email': 'alice@jetleaf.dev',
      },
      'unsafeHtml': '<script>alert("XSS")</script>',
    },
  );

  final asset = AssetResource(templateHtml);
  final rendered = jtl.render(template, asset);

  print('Rendered Output:\n${rendered.getRenderedContent()}');

  // 2. Custom Filter Registration
  print('[2] Custom Filter Registry:');
  final filters = jtl.getFilterRegistry();
  filters.registerFilter('shout', (val) => '${val.toString().toUpperCase()}!!!');
  final shoutFn = filters.getFilter('shout');
  print('Registered filter "shout" -> result: ${shoutFn?.call('hello world')}');

  print('\n========================================================');
  print('  ✅ JTL Example executed successfully!');
  print('========================================================');
}
1
likes
160
points
243
downloads

Documentation

Documentation
API reference

Publisher

verified publisherhapnium.com

Weekly Downloads

Jetleaf Template Language — a lightweight, high-performance template engine for generating HTML, text, and dynamic content.

Homepage
Repository (GitHub)
View/report issues

Topics

#templates #rendering #jetleaf #html #dynamic-content

License

BSD-2-Clause (license)

Dependencies

jetleaf_core

More

Packages that depend on jtl