# 參考網址
http://code.google.com/intl/zh-TW/closure/templates/docs/helloworld_js.html
# 目的
跟Smarty差不多,就是把版(html)與程式碼(javascript)分離
# 範例
# 也是看google所寫的範例去使用
# 假設現在在~/ (linux home directory)
$ mkdir worktestdir
$ cd worktestdir
$ wget http://closure-templates.googlecode.com/files/closure-templates-for-javascript-latest.zip
$ unzip closure-templates-for-javascript-latest.zip
解開後會有一些檔案,主要是這兩個檔案
SoyToJsSrcCompiler.jar -> 這個是把soy(template檔案)編輯成js的檔案,當然是需要java,而且是要java6以上的版本
soyutils.js -> html需要在使用這個js,當做範本的engine(雖然google把它當做tool,不過我還是當它是engine)
$ vi simple.soy
{namespace examples.simple}
/**
* Says hello to the world.
*/
{template .helloWorld}
Hello world!
{/template}
*其中上面那一行namespace是一定要加上去的,那是對該範本檔做名稱的定義
把soy檔案編譯成js
$ java -jar SoyToJsSrcCompiler.jar  --outputPathFormat simple.js   simple.soy
建立html檔案
$ vi index.html
文章標籤

付爸爸 發表在 痞客邦 留言(0) 人氣(282)