您的位置:首页 > 其它

play framework学习笔记之 模板引擎

2011-04-17 16:57 399 查看
模板语法

${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 文件里



[code]clientName=The client name is %s



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



[code]<h1>&{'clientName','myname' }</h1>

[code]得到的结果是
<h1>The client name is myname</h1>[/code]






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



[code]页面内容    Hello from tag!



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

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



[code]如:   #{hello /}

[code]给自定义标签加参数

[code]比如你在  hello.html 里面 用到  
${_name} name前面加 _[/code]
那么

#{hello name:'Bob' /} 可以这样赋值

当然也有默认的唯一参数的时候  arg

Example:
[code][code]Hello ${_arg}!

And you can call it easily using:

[code]#{hello 'Bob' /}

[code]

[/code]
调用标签体   Invoke tag body

Hello #{doBody /}!


#{hello} 

 Bob 

#{/hello}

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

[/b][/code]
[code]

默认的模板页面是在 views/tags 目录下,如果再在其下 建立 文件夹 比如 a
[/code]
则就有了 命名空间  #{a.xxx /}


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: