Skip to content
hiroy edited this page Nov 18, 2011 · 2 revisions

JsRender

使い方

var commentContent = "aiueo";
$.template("commentTemplate", "<div>{{=comment}}</div>");
var comment = $.render({comment: commentContent}, "commentTemplate");
$(comment).insertBefore($("#commentButton"));

Tips

  • デフォルトでHTMLエスケープされる
  • HTMLエスケープされたくない場合は{{=comment!none}}とencode方法を付記する感じ
  • AjaxでHTMLを含んだ内容が取得できる場合とか
  • ifとかeachとか制御構造も書ける
  • テンプレート内容については変数ではなくscript[type=text/html]な部分に記述することも可能

Clone this wiki locally