0

我是新的游戏。我一直在阅读提供游戏框架的教程和示例。我可以成功渲染 playframework 示例提供的 helloworld 应用程序。我对 main.scala.html 的渲染部分毫无疑问。#

这是我从samples/helloworld获得的默认程序

@(title: String)(content: Html)

<!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.6.4.min.js")" type="text/javascript"></script>
    </head>
    <body>

        <header>
            <a href="@routes.Application.index">@title</a>
        </header>

        <section>
            @content
        </section>

    </body>
</html>

在这里,当我注释掉 section tag 下的 @content 时,我看不到这些字段。现在我的问题是,@content 在哪里映射到表单字段?

我为我的布局创建了另一个结构并将@content 添加到内容部分。但它不适合,所以现在我的问题是@content 在哪里定义它是 div 容器并且有一些高度和重量等等?我无法理解。请帮我。请在下面找到我的自定义代码

@(title: String)(content: Html)

<!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.7.1.min.js")" type="text/javascript"></script>
    </head>


<body>

<div id="container" style="width:500px">

<div id="header" style="background-color:#FFA500;">
<h1 style="margin-bottom:0;">Main Title of Web Page</h1></div>

<div id="menu" style="background-color:#FFD700;height:200px;width:100px;float:left;">
<b>Menu</b><br>
HTML<br>
CSS<br>
JavaScript</div>

<div id="content" style="background-color:#EEEEEE;height:200px;width:400px;float:left;">
@content</div>

<div id="footer" style="background-color:#FFA500;clear:both;text-align:center;">
Copyright © W3Schools.com</div>






</body>


</html>
4

1 回答 1

0

介绍

从播放模板文档中的模板参数中,描述了第一行的含义。在这里,我们看到需要两个参数组。

两个参数组是:

  1. String包含标题的参数
  2. Html包含一些 HTML 内容的参数

用法

要使用此模板,必须提供两个参数组。在 helloworld 应用程序的上下文中,它是app/views/index.scala.html这样调用的:

@main(title = "The 'helloworld' application") {
  <h1>Configure your 'Hello world':</h1>
  ... more HTML elided
}

此模式在http://www.playframework.com/documentation/2.2.x/ScalaTemplateUseCases中进行了描述,其中 HTML 被注入到模板中。

  • main.scala.html包含模板(content包含要注入的 HTML)。
  • index.scala.html包含注入此模板的示例。

请注意,调用会调用 .@main(...)中定义的模板。main.scala.html同样,调用@my_template(...)会调用 . 中定义的模板my_template.scala.html

在这种情况下,表单的 HTML 在内部定义index.scala.html

调用模板

最后,从控制器调用根模板。对于 helloworld 应用程序,定义的模板index.scala.html由代码调用

def index = Action {
  Ok(html.index(helloForm))
}

这是将表单对象注入模板的地方。

于 2014-05-29T11:19:09.283 回答