はじめに
よく使う機能で、公式に詳しいサンプルが無かったものをメモ。
テンプレートの機能を知りたい場合はまず以下に目を通すこと。
テンプレートエンジン
テンプレートのチートシート
テンプレートで使う記号
&'あああ' メッセージ
$ dto
タグ
% スクリプト
よく使う機能
#{set 'moreScripts'}の書き方
#{set 'moreScripts'}
#{script 'jquery.validate.min.js'/}
#{script 'myjs.js'/}
#{/set}
#{set 'moreStyles'}の書き方
#{set 'moreStyles'}
#{stylesheet 'mycss.css' /}
#{/set}
formタグにHTML要素を追加する
#{form @Application.update(), id:'update_form', class:'form', role:'form'}
#{/form}
formタグに追加したい要素をカンマで区切って追加できます。
式(${})をタグの中に記述する
タグの中に式(${})を記述してidやClass名を作ることができます。
<button type="button" id=${user.id}>${user.name}</button>
コレクションをループで処理する
#{list items:sections, as:'section'}
#{list items:section.employees, as:'employee'}
<td>${employee.name}</td>
#{/list}
#{/list}
コレクションのループでインデックスを使う
#{list items:users, as:'user'}
#{if user_index <= 2}
<!-- インデックスが2以下の時の処理 -->
#{/if}
#{else}
<!-- インデックスが3以上の時の処理 -->
#{/else}
#{/list}