和你编写代码类似,你编写的页面也可以由多个小的片段组合而成,这些小的片段本身也可以由更小的片段构成。这些小片段通常是可以在其它页面重复使用的:有些部分可以用在所有页面,而有些部分是某些页面特定的。本篇介绍如何使用这些可重用的小模板来构成整个页面。
Includes
到目前为止的例子,我们只显示了HTML的片段,没有实例显示整个页面。下面我们给出完整的显现产品列表的代码和模板:
1 |
def catalog() = Action { |
2 |
val products = ProductDAO.list |
3 |
Ok(views.html.shop.catalog(products)) |
4 |
} |
对应的页面模板app/views/products/catalog.scala.html
1 |
@ (products : Seq[Product]) |
2 |
<!DOCTYPE html> |
3 |
<html> |
4 |
<head> |
5 |
<title>paperclips.example.com</title> |
6 |
<link href = "@routes.Assets.at(" stylesheets/main.css ")" |
7 |
rel = "stylesheet" > |
8 |
</head> |
9 |
<body> |
10 |
<div id = "header" > |
11 |
|