Play frame (iii) template

Source: Internet
Author: User
Tags html page

In the previous section, I returned the string to the customer via OK (). I can put a complete HTML page into the string to return. However, modern frameworks provide a better way--templates. The template separates the view from the data. The server can pass different data to the same template, resulting in different pages. Play also has a template system. Most of the template's content can be written in HTML, as a view, and in some special place, the data parameters are reserved. In the template, use the Scala language to invoke the arguments.

Working with templates

I first create a template that is purely view-capable. In the App/views folder, create a new file index.scala.html (delete and recreate it if you have one).

<! DOCTYPE html>   

This template is a pure HTML file and is the simplest form of template.

Modify App/controllers/application.java:

package controllers;   
       
Import play.*;   
Import play.mvc.*;   
       
       
public class Application extends Controller {public   
    static result index () {return   
        OK (views.html.index.render ());   
    }   
}

Ok () is receiving views.html.index.render (), which is actually the render () method of the app/views/index.scala.html template. Play will automatically generate the corresponding class according to the template.

You can also use import to introduce Views.html.index, rather than using the full classpath.

Access page:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.