日頃の行い

個人的な日頃の行いをつらつら書いてます\\\\ ٩( 'ω' )و ////

Scala Play Framework のmain.scala.html #2

ScalaフレームワークPlay Frameworkで遊んでるけど仕組みが未だによくわからないからメモを書きまくる。

app/views/main.scala.html

@(title: String)(content: Html)(footer: Html)

<!DOCTYPE html>

<html>
    <head>
        <title>@title</title>
    </head>
    <body>
    <div class="container">
    @content
    @footer
    </div> <!-- /container -->
    </body>
</html>

この時、1行目の @(title) (content) (footer)
と書かないと、下のhtml文書に変数として記述してもエラーが吐かれる。
(たしか(´・ω・`)w)

app/views/index.scala.html

@main(title="hoge"){
    <h1>Hello(from template)</h1>
}{
    <hr />
    <p class="text-info">footer</p>
}

このhtmlは main.scala.html を呼び出していて、
@main(hoge){fuga}{bar}
で、
hoge → title
fuga → content
bar → footer
が main.scala.html の宣言された変数に順番通り対応している。
(たぶん(´・ω・`)w)

上の例のように title="hoge" と変数指定して値を渡すことも出来る。
なので、以下のように新しく変数を追加したら

app/views/main.scala.html

@(title: String)(content: Html)(footer: Html)(footer_second: Html)

<!DOCTYPE html>

<html>
    <head>
        <title>@title</title>
    </head>
    <body>
    <div class="container">
    @content
    @footer
    @footer_second
    </div> <!-- /container -->
    </body>
</html>

app/views/index.scala.html

@main(title="hoge"){
    <h1>Hello(from template)</h1>
}{
    <hr />
    <p class="text-info">footer</p>
}{
    <p>ここにfooter_second</p>
}

となるはず。
(たぶん(´・ω・`))