如何使用小胡子文件作为飞镖中模板的来源?
How to use a mustache file as the source of a template in dart?
在golang中你可以传递一个文件作为模板的来源,例如:
t, err := template.ParseFiles("hello.gohtml")
但我想不通,如何使用 mustache 包在 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>
您可以读取文件然后解析它:
var template = Template(File('hello.mustache').readAsStringSync());
在golang中你可以传递一个文件作为模板的来源,例如:
t, err := template.ParseFiles("hello.gohtml")
但我想不通,如何使用 mustache 包在 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>
您可以读取文件然后解析它:
var template = Template(File('hello.mustache').readAsStringSync());