Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use an html page as a view in play framework 2?

I am fairly new to Play 2.0 - I try searching for samples but always keep on getting Scala templates as the view for directing the content to, is it possible to just use a non Scala based, pure html file as a view? How do you ask the Controller's action method to direct it to that html file?

like image 483
user2627953 Avatar asked Aug 01 '13 23:08

user2627953


People also ask

What is twirl template?

A type safe template engine based on Scala Play comes with Twirl, a powerful Scala-based template engine, whose design was inspired by ASP.NET Razor. Specifically it is: compact, expressive, and fluid: it minimizes the number of characters and keystrokes required in a file, and enables a fast, fluid coding workflow.

Is play a Java framework?

Play is a high-productivity web application framework for programming languages whose code is compiled and run on the JVM, mainly Java and Scala. It integrates the components and APIs we need for modern web application development.

Is Play Framework MVC?

A play application follows the MVC architectural pattern applied to the Web architecture. This pattern splits the application into separate layers: the Presentation layer and the Model layer. The Presentation layer is further split into a View and a Controller layer.

Why play framework is used?

Play Framework makes it easy to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly architecture. Built on Akka, Play provides predictable and minimal resource consumption (CPU, memory, threads) for highly-scalable applications.


1 Answers

First, put your HTML files in the public folder, for example:

public
  |
  ├── html
      |
      └── hello.html 

And then you can serve static HTML files using several ways with the Assets controller:

Either by refering to the file directly in the Url: http://localhost:9000/assets/html/hello.html

Either by using the routes file to map an Url to your file. In the routes file, add:

GET /hello  controllers.Assets.at(path="/public", file="html/hello.html")

Then access the Html using http://localhost:9000/hello

like image 54
ndeverge Avatar answered Sep 19 '22 16:09

ndeverge