带模板的Javascript(nodejs)模板

带模板的Javascript(nodejs)模板,javascript,node.js,html,templates,Javascript,Node.js,Html,Templates,我想在服务器端构建我的html代码 为此,我使用了Plates,它是一个模板javascript库。 我试图让这个代码工作,但它只是不修改原始的html模板代码 var Plates = require("plates") var html = "<h1>Template test with plates</h1>" + "<p my-content>This should be erased...</p>"; v

我想在服务器端构建我的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板=需要(“板”)
var html=“使用板进行模板测试”
+“这应该被删除…

”; var data={‘我的内容’:“它是:“+new Date()}”; console.log(Plates.bind(html,data));
这应该输出日期而不是默认字符串,但它不

我也试过使用mapper,但没有成功:

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板=需要(“板”)
var html=“透明模板测试”
+“这应该被删除…

”; 变量数据={'content':“它是:->”+新日期(); var map=Plates.map(); map.where('my-content')。使用('content'); console.log(Plates.bind(html、数据、地图));
我得到的唯一代码示例如下所示:

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));
var板=需要(“板”)
var html=“透明模板测试”
+“这应该被删除…

”; 变量数据={'content':“它是:->”+新日期(); var map=Plates.map(); 映射。其中('my-content')。是(“可变的”)。使用('content'); console.log(Plates.bind(html、数据、地图));
但是我不需要
my content='change'
标签,我只需要
my content
标签

有人能帮我吗


我还接受其他nodejs模板库的建议,这些建议与此类似(如果这解决了我的问题).

您的代码不起作用,因为您将
我的内容
用作属性

您需要使用
id
属性,并将其更改为

,bind()才能工作

e、 g

var板=需要(“板”)
var html='带板的模板测试'
+“

这应该被删除…

”; var data={‘我的内容’:“它是:“+new Date()}”; console.log(Plates.bind(html,data));
您的代码不起作用,因为您将
我的内容
用作属性

您需要使用
id
属性,并将其更改为

,bind()才能工作

e、 g

var板=需要(“板”)
var html='带板的模板测试'
+“

这应该被删除…

”; var data={‘我的内容’:“它是:“+new Date()}”; console.log(Plates.bind(html,data));
是的,我同意,但在我的第三个代码示例中,我使用了
我的内容
作为一个具有值的属性(在这种情况下它工作正常)。。。我需要使用属性(没有属性值)来模板我的HTML。。。。是否有一种使用“Plates”的解决方案,或者可能有一个类似的模板引擎,允许我基于无价值的HTML属性来模板我的HTML?是的,我同意,但在我的第三个代码示例中,我将
我的内容
用作具有值的属性(在这种情况下工作正常)。。。我需要使用属性(没有属性值)来模板我的HTML。。。。难道没有一个使用“Plates”的解决方案,或者可能会有一个类似的模板引擎,允许我基于无价值的HTML属性来模板HTML吗?
var Plates = require("plates")

var html    = '<h1>Template test with plates</h1>'
            + '<p id="my-content">This should be erased...</p>';

var data = { 'my-content': "It is: "+new Date() };

console.log(Plates.bind(html, data));