LoginSignup
8
8

More than 5 years have passed since last update.

PlayFramework1.2のview(テンプレート)でよく使う機能

Last updated at Posted at 2014-03-28

はじめに

よく使う機能で、公式に詳しいサンプルが無かったものをメモ。
テンプレートの機能を知りたい場合はまず以下に目を通すこと。
テンプレートエンジン
テンプレートのチートシート

テンプレートで使う記号

&'あああ' メッセージ
$ 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}
8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8