现在的位置: 首页 > 综合 > 正文

play framework学习笔记之 模板引擎

2013年10月18日 ⁄ 综合 ⁄ 共 1372字 ⁄ 字号 评论关闭

模板语法

${client.name}

${client?.name}  不能确定client是否存在的时候?

 

 

 #{extends /}

 

#{doLayout /}

#{get}

#{set} 

 

比如

#{extends 'simpledesign.html' /}
 

#{set title:'A decorated page' /} 

 

 

Tags: #{tagName /}

#{script 'jquery.js' /}

 

#{list items:client.accounts, as:'account' }   循环

<li>${account}</li>

#{/list}

 

 

 

Actions: @{…} or @@{…}

<a href="@{Clients.showAccounts(client.id)}">All accounts</a> 

 

注意此时Clients.showAccounts(client.id)没有加引号

<link rel="stylesheet" media="screen" href="@{'/public/stylesheets/main.css'}">

这些其它的public内的资源 需要   ' /public/stylesheets/main.css '  内部加引号的,特别注意

@{…}相对路径

 

@@{…}绝对路径

 

 

Messages: &{…}

 

 

 

 

 

比如  conf/messages 文件里

 

clientName=The client name is %s

 

在模板页面里面使用&{…}

 

<h1>&{'clientName','myname' }</h1>
得到的结果是  <h1>The client name is myname</h1>

 

 

 

Comment: *{…}*  注释

*{**** Display the user name ****}*

 

%{…}% 类似过去的JSP页面一样在页面里嵌入逻辑

%{
fullName = client.name.toUpperCase()+' '+client.forname;
}%

<h1>Client ${fullName}</h1>

 

 

 

To create a hello tag, just create the app/views/tags/hello.html file.

比如创建一个hello标签,只需要建立页面app/views/tags/hello.html

 

页面内容    Hello from tag!

 

No need to configure anything. You can use the tag directly:

不需要配置别的东西,你可以直接使用此标签

 

如:   #{hello /}
给自定义标签加参数
比如你在  hello.html 里面 用到  ${_name}   name前面加 _
那么
#{hello name:'Bob' /} 可以这样赋值
当然也有默认的唯一参数的时候  arg

Example:

Hello ${_arg}!

And you can call it easily using:

#{hello 'Bob' /}

调用标签体   Invoke tag body
Hello #{doBody /}!

#{hello} 
 Bob 
#{/hello}
这样通过 
#{doBody /}      Bob 就作为标签体  传入了 自定义标签


默认的模板页面是在 views/tags 目录下,如果再在其下 建立 文件夹 比如 a

则就有了 命名空间  #{a.xxx /}

 

 

 

 

 

 

抱歉!评论已关闭.