如何在Dart中使用小胡子文件作为模板的来源?

时间:2019-06-21 02:33:38

标签: dart mustache

在golang中,您可以传递文件作为模板的来源,例如:

t, err := template.ParseFiles("hello.gohtml")

但是我不知道如何使用小胡子包在dart中执行此简单操作。

我认为,这与此相似。但这只是打印 hello.mustache

main.dart

import 'package:mustache/mustache.dart';

main() {
 var data = { 'name': 'foo' };
 var template = new Template('hello.mustache');

 var output = template.renderString(data);
 print(output);
}

hello.mustache

<h1>hello, {{name}}</h1>

1 个答案:

答案 0 :(得分:0)

您可以读取文件然后对其进行解析:

var template = Template(File('hello.mustache').readAsStringSync());