1

私は Play フレームワークを学習しています & ルート テンプレートに表示される動的なサイドバー/フッターを作成する方法を考えていました & すべてのビューをレンダリングするときに明示的にデータを渡す必要はありません. docsを読みましたが、これについては何もありませんでした。

Django では、このためのカスタム テンプレート タグを作成します。Playにも同様のものはありますか?これを解決するための最良/典型的なアプローチは何ですか?

4

1 に答える 1

3

play2 のどこにでもパラメータを渡さないようにするにはどうすればよいですか? http://jazzy.id.au/default/2012/10/26/passing_common_state_to_templates_in_play_framework.html は非常に役に立ちます。

たとえば、テンプレート footer.scala.html、main.scala.html、および header.scala.html を使用できます。

main.scala.html は次のようになります。

@(title: String)(content: Html)(implicit x: SomeType)

<!DOCTYPE html>

<html>
    <head>
        <title>@title</title>
        <link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
        <link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
        <script src="@routes.Assets.at("javascripts/jquery-1.9.0.min.js")" type="text/javascript"></script>
    </head>
    <body>
        @header() @* include the header *@
        @content  @* will resolve to "the content" for index.scala.html *@
        @footer() @* include the footer *@
    </body>
</html>

また、index.scala.html などのページ テンプレート:

@(message: String)(implicit x: SomeType)

@main("Welcome to Play 2.1") {
    the content
}

フッターまたはヘッダーは、x: SomeType を暗黙的なメソッド パラメーターとして使用して、動的コンテンツを配信できます。

于 2013-09-03T19:00:32.360 に答える