【发布时间】:2015-08-12 14:40:46
【问题描述】:
我想在服务器端构建我的 html 代码。
为此,我使用了 Plates,它是一个模板化的 JavaScript 库。
我试图让这段代码工作,但它只是不修改原始的 html 模板代码......
var Plates = require("plates")
var html = "<h1>Template test with plates</h1>"
+ "<p my-content>This should be erased...</p>";
var data = { 'my-content': "It is: "+new Date() };
console.log(Plates.bind(html, data));
这应该输出日期而不是默认字符串,但它不会...
我也尝试过使用映射器,但它没有成功:
var Plates = require("plates")
var html = "<h1>Template test with transparency</h1>"
+ "<p my-content>This should be erased...</p>";
var data = { 'content': "It is: -> "+new Date() };
var map = Plates.Map();
map.where('my-content').use('content');
console.log(Plates.bind(html, data, map));
我得到的唯一代码示例如下:
var Plates = require("plates")
var html = "<h1>Template test with transparency</h1>"
+ "<p my-content='changeable'>This should be erased...</p>";
var data = { 'content': "It is: -> "+new Date() };
var map = Plates.Map();
map.where('my-content').is("changeable").use('content');
console.log(Plates.bind(html, data, map));
但我不需要my-content='changeable' 标签,我只需要my-content 标签...
有人可以帮我吗?
我也接受其他与此类似的 nodejs 模板库建议(如果这解决了我的问题)...
【问题讨论】:
标签: javascript node.js html templates