瀏覽代碼

explained why templish exists

master
mort 8 年之前
父節點
當前提交
864d1d2975
共有 1 個檔案被更改,包括 19 行新增0 行删除
  1. 19
    0
      README.md

+ 19
- 0
README.md 查看文件

@@ -2,6 +2,25 @@

A templating language for JavaScript, using JavaScript.

## Why?

There are other templating languages out there. However, most of them don't really let you have a lot of logic in your templates. While those languages have their uses, it's often useful to have some logic in your templates.

Templish isn't meant to be used like traditional bad PHP code, hvere you have view logic and business logic in the same file with little to no distinction; most people will want to have each template stored in its own file, and have all business logic handled outside of templates, like you would with any other node.js web server. An example of a case where you would want logic in your templates is a list template where you want to alternate the color of the entries. With templish, this could be achieved like this:

``` JavaScript
<ul>{{
var str = "";
rows.forEach(function(row, i) {
var c = "type"+(i % 2);
str += "<li class='"+c+"'>"+row+"</li>";
});
return str;
}}</ul>
```

With a templating language which does not allow arbitrary logic, things like that may have to be done in a more complicated way outside of templates.

## Installation

Install with NPM:

Loading…
取消
儲存