模板修饰符:#{extends /} ,#{doLayout /}
在模板和修饰器之间,使用#{get} 和#{set}标签 共享变量 。
#{extends 'simpledesign.html' /}
#{set title:'A decorated page' /}
This content will be decorated.
修饰器:simpledesign.html
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>#{get 'title' /}</title>
<link rel="stylesheet" type="text/css" href="@{'/public/stylesheets/main.css'}" />
</head>
<body>
<h1>#{get 'title' /}</h1>
#{doLayout /}
<div class="footer">Built with the play! framework</div>
</body>
</html>
标签: #{tagName /}
list标签有两个强制性的参数:items和as
<h1>Client ${client.name}</h1>
<ul>
#{list items:client.accounts, as:'account' }
<li>${account}</li>
#{/list}
</ul>
消息:&{…}
如果你的应用需要国际化,你可以使用 &{…} 来显示本地化消息:
例如在文件 conf/messages 我们指定:
clientName=The client name is %s
在模板中展示消息, 只需这样:
<h1>&{'clientName', client.name}</h1>
脚本:%{…}%
脚本能声明一些变量和定义一些语句。使用 %{…}% 插入脚本。
%{
fullName = client.name.toUpperCase()+' '+client.forname;
}%
<h1>Client ${fullName}</h1>
使用out对象,脚本能直接输出动态的内容 :
%{
fullName = client.name.toUpperCase()+' '+client.forname;
out.print('<h1>'+fullName+'</h1>');
}%
你可以使用脚本来创建一个框架,例如:
<h1>Client ${client.name}</h1>
<ul>
%{
for(account in client.accounts) {
}%
<li>${account}</li>
%{
}
}%
</ul>
记住,模板不是用来做复杂事情的地方。因此, 当你有需要的时候才使用标签,或者把计算过程移进控制器里面进行。