JsHtml 提供简洁的 HTML、全 JavaScript 的模版引擎,灵感来自 ASP.NET MVC 中的 razor 视图引擎。可在浏览器使用,也支持 Node.js 。
示例模版 index.jshtml:
<html> <head> <title>@locals.title</title> </head> <body> <ul class="Task"> @locals.taskList.forEach(function(task, index) { <li class="@(index % 2 ? "Odd" : "Even")"> @tag('a', {href: '/task/' + task.id}, task.name) </li> }); </ul> <ul class="Task"> @for(var taskIndex = 0, taskCount = locals.taskList.length; taskIndex < taskCount; taskIndex ++){ writePartial('task', {taskIndex: taskIndex, task: locals.taskList[taskIndex]}); } </ul> <p> if you like it, let me know!<br /> - <a href="mailto:elmerbulthuis@gmail.com">elmerbulthuis@gmail.com</a><br /> </p> </body> </html>