Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
314 lines (230 sloc) 12.141 kB
@(message: String, style: String = "Scala")
@play.api.Play.maybeApplication.filterNot(_.mode != play.api.Mode.Dev).map { _ =>
<link rel="stylesheet" media="screen" href="/@@documentation/resources/style/main.css">
<section id="top">
<div class="wrapper">
<h1><a href="/@@documentation">@message</a></h1>
<nav>
<span class="versions">
<span>Browse APIs</span>
<select onchange="document.location=this.value">
<option selected disabled>Select language</option>
<option value="/@@documentation/api/scala/index.html">Scala</option>
<option value="/@@documentation/api/java/index.html">Java</option>
</select>
</span>
</nav>
</div>
</section>
<div id="news">
<iframe src="http://www.playframework.com/widget?uid=@play.api.Play.maybeApplication.flatMap(_.configuration.getString("application.secret")).map(_.take(5)).map(play.api.libs.Codecs.sha1(_))&version=@play.core.PlayVersion.current&tag=@style.toUpperCase" scrolling="no" style="overflow: hidden; display: block; margin: 0 auto; width: 960px; height: 60px"></iframe>
</div>
<div id="content" class="wrapper doc">
@if(style == "Scala") {
<article>
<h1>Welcome to Play</h1>
<p>
Congratulations, you’ve just created a new Play application. This page will help you with the next few steps.
</p>
<blockquote>
<p>
You’re using Play @play.core.PlayVersion.current
</p>
</blockquote>
<h2>Why do you see this page?</h2>
<p>
The <code>conf/routes</code> file defines a route that tells Play to invoke the <code>Application.index</code> action whenever a browser requests the <code>/</code> URI using the GET method:
</p>
<pre><code># Home page
GET / controllers.Application.index</code></pre>
<p>
Play has invoked the <code>controllers.Application.index</code> method to obtain the <code>Action</code> to execute:
</p>
<pre><code>def index = Action {
Ok(views.html.index("Your new application is ready!"))
}</code></pre>
<p>
An action is a function that handles the incoming HTTP request, and returns the HTTP result to send back to the web client.
Here we send a <code>200 OK</code> response, using a template to fill its content.
</p>
<p>
The template is defined in the <code>app/views/index.scala.html</code> file and compiled as a Scala function.
</p>
<pre><code>@@(message: String)
@@main("Welcome to Play") {
@@play20.welcome(message)
}</code></pre>
<p>
The first line of the template defines the function signature. Here it just takes a single <code>String</code> parameter.
This template then calls another function defined in <code>app/views/main.scala.html</code>, which displays the HTML layout, and another
function that displays this welcome message. You can freely add any HTML fragment mixed with Scala code in this file.
</p>
<h2>Is this your first time?</h2>
<p>
If you're not already using it, checkout out <a href="https://typesafe.com/activator">Activator</a>.
If you start the Activator UI, by running:
</p>
<pre><code>$ activator ui</code></pre>
<p>
You can get access to great templates and tutorials that demonstrate how to write Play applications.
</p>
<h2>Need to set up an IDE?</h2>
<p>
You can start hacking your application right now using any text editor. Any changes will be automatically reloaded at each page refresh,
including modifications made to Scala source files.
</p>
<p>
If you want to set-up your application in <strong>Eclipse</strong> or any other Scala IDE, check the
<a href="/@@documentation/IDE">Setting up your preferred IDE</a> page.
</p>
<h2>Need to connect to a database?</h2>
<p>
You can quickly set-up a development database (either in-memory or written to the file system),
by adding these lines to the <code>conf/application.conf</code> file:
</p>
<pre><code>db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"</code></pre>
<p>
If you need to connect to another JDBC-compliant database, first add the corresponding driver library
to your application dependencies in build.sbt e.g.:
</p>
<pre><code>libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.36"
</code></pre>
<p>
Then add the corresponding JDBC configuration to the <code>conf/application.conf</code> file:
</p>
<pre><code>db.url=jdbc:mysql:database_name
db.driver=org.mysql.Driver
db.user=root
db.pass=secret</code></pre>
<h2>Need more help?</h2>
<p>
When your application is run from the Play console, you can access the current documentation directly, at
the <a href="/@@documentation">/@@documentation</a> URL or go to <a href="http://www.playframework.com">http://www.playframework.com</a>.
</p>
<p>
The <a href="http://groups.google.com/group/play-framework">Play Google Group</a> is where Play users come to seek help, announce projects, and discuss issues and new features. If you don’t have a Google account, you can still join the mailing list by sending an e-mail to
<strong>play-framework+subscribe@@googlegroups.com</strong>.
</p>
</article>
<aside>
<h3>Browse</h3>
<ul>
<li><a href="/@@documentation">Local documentation</a></li>
<li><a href="/@@documentation/api/scala/index.html">Browse the Scala API</a></li>
</ul>
<h3>Start here</h3>
<ul>
<li><a href="/@@documentation/PlayConsole">Using the Play console</a></li>
<li><a href="/@@documentation/IDE">Setting up your preferred IDE</a></li>
</ul>
</aside>
} else {
<article>
<h1>Welcome to Play</h1>
<p>
Congratulations, you’ve just created a new Play application. This page will help you with the next few steps.
</p>
<blockquote>
<p>
You’re using Play @play.core.PlayVersion.current
</p>
</blockquote>
<h2>Why do you see this page?</h2>
<p>
The <code>conf/routes</code> file defines a route that tells Play to invoke the <code>Application.index</code> action whenever a browser requests the <code>/</code> URI using the GET method:
</p>
<pre><code># Home page
GET / controllers.Application.index()</code></pre>
<p>
Play has invoked the <code>controllers.Application.index</code> method:
</p>
<pre><code>public static Result index() {
return ok(index.render("Your new application is ready."));
}</code></pre>
<p>
An action method handles the incoming HTTP request, and returns the HTTP result to send back to the web client.
Here we send a <code>200 OK</code> response, using a template to fill its content.
</p>
<p>
The template is defined in the <code>app/views/index.scala.html</code> file and compiled as a standard Java class.
</p>
<pre><code>@@(message: String)
@@main("Welcome to Play") {
@@play20.welcome(message, style = "Java")
}</code></pre>
<p>
The first line of the template defines the function signature. Here it just takes a single <code>String</code> parameter.
Then this template calls another function defined in <code>app/views/main.scala.html</code> which displays the HTML layout, and another
function that displays this welcome message. You can freely add any HTML fragment mixed with Scala code in this file.
</p>
<blockquote>
<p>
<strong>Note</strong> that Scala is fully compatible with Java, so if you don’t know Scala don’t panic, a Scala statement is very similar to a Java one.
</p>
</blockquote>
<h2>Is this your first time?</h2>
<p>
If you're not already using it, checkout out <a href="https://typesafe.com/activator">Activator</a>.
If you start the Activator UI, by running:
</p>
<pre><code>$ activator ui</code></pre>
<p>
You can get access to great templates and tutorials that demonstrate how to write Play applications.
</p>
<h2>Need to set up an IDE?</h2>
<p>
You can start hacking your application right now using any text editor. Any changes will be automatically reloaded at each page refresh,
including modifications made to Scala source files.
</p>
<p>
If you want to set-up your application in <strong>Eclipse</strong> or any other Java IDE, check the
<a href="/@@documentation/IDE">Setting up your preferred IDE</a> page.
</p>
<h2>Need to connect to a database?</h2>
<p>
You can quickly set-up a development database (either in-memory or written to the file system),
by adding these lines to the <code>conf/application.conf</code> file:
</p>
<pre><code>db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"</code></pre>
<p>
If you need to connect to another JDBC-compliant database, first add the corresponding driver library
to your application dependencies in build.sbt e.g.:
</p>
<pre><code>libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.36"
</code></pre>
<p>
Then add the corresponding JDBC configuration to the <code>conf/application.conf</code> file:
</p>
<pre><code>db.url=jdbc:mysql:database_name
db.driver=org.mysql.Driver
db.user=root
db.pass=secret</code></pre>
<h2>Need more help?</h2>
<p>
When your application is run from the Play console, you can access the current documentation directly, at
the <a href="/@@documentation">/@@documentation</a> URL or go to <a href="http://www.playframework.com">http://www.playframework.com</a>.
</p>
<p>
The <a href="http://groups.google.com/group/play-framework">Play Google Group</a> is where Play users come to seek help, announce projects, and discuss issues and new features. If you don’t have a Google account, you can still join the mailing list by sending an e-mail to
<strong>play-framework+subscribe@@googlegroups.com</strong>.
</p>
</article>
<aside>
<h3>Browse</h3>
<ul>
<li><a href="/@@documentation">Local documentation</a></li>
<li><a href="/@@documentation/api/java/index.html">Browse the Java API</a></li>
</ul>
<h3>Start here</h3>
<ul>
<li><a href="/@@documentation/PlayConsole">Using the Play console</a></li>
<li><a href="/@@documentation/IDE">Setting up your preferred IDE</a></li>
</ul>
</aside>
}
</div>
}.getOrElse {
<h1>@message</h1>
}
Jump to Line
Something went wrong with that request. Please try again.