0

I am new playwork. I have been going through the tutorials and samples provided the playframework. I could successfully render helloworld application provided by playframework samples. I have few doubts regarding the rendering part of main.scala.html.#

This is the default program which I got from 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>

Here when I commented out the @content under section tag , I am not able to see the the fields. Now my question is, where is @content is mapped to the Form field?

I created another structure for my layout and added the @content to the content section. but it does not fit into that so now my question is @content where is that defined that it is div container and has got some height and weight and all? I could not understand. Please help me. Pleae find my customized code below

@(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>
JavaPassion
  • 112
  • 1
  • 1
  • 7

1 Answers1

0

Introduction

From Template parameters in the Play Template documentation, the meaning of the first line is described. Here, we see that two parameter groups are required.

The two parameter groups are:

  1. a String parameter containing the title
  2. a Html parameter containing some HTML content

Usage

To use this template, two parameter groups have to be supplied. In the context of the helloworld application, it is called from app/views/index.scala.html like this:

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

This pattern is described in http://www.playframework.com/documentation/2.2.x/ScalaTemplateUseCases, where HTML is injected into a template.

  • main.scala.html contains the template (content contains the HTML to be injected).
  • index.scala.html contains an example of injection into this template.

Note that calling @main(...) calls the template that is defined in main.scala.html.Similarly, calling @my_template(...) would call the template defined in my_template.scala.html.

In this case, the HTML for the form is defined inside index.scala.html.

Calling the Template

Finally, the root template is called from a controller. For the helloworld application, the template defined in index.scala.html is invoked by the code

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

This is where the form object is injected into the template.

Gary Coady
  • 1,196
  • 9
  • 13