play framework学习笔记之 模板引擎
2011-04-17 16:57
399 查看
模板语法
${client.name}
${client?.name} 不能确定client是否存在的时候?
#{set}
比如
#{extends 'simpledesign.html' /}
#{set title:'A decorated page' /}
#{list items:client.accounts, as:'account' } 循环
<li>${account}</li>
#{/list}
注意此时Clients.showAccounts(client.id)没有加引号
而
<link rel="stylesheet" media="screen" href="@{'/public/stylesheets/main.css'}">
这些其它的public内的资源 需要 ' /public/stylesheets/main.css ' 内部加引号的,特别注意
在模板页面里面使用&{…}
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
No need to configure anything. You can use the tag directly:
不需要配置别的东西,你可以直接使用此标签
And you can call it easily using:
[/code]
[/b][/code]
默认的模板页面是在 views/tags 目录下,如果再在其下 建立 文件夹 比如 a[/code]
${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 /}
相关文章推荐
- play framework学习笔记之 模板引擎
- php学习笔记-3.thinkphp表的join和模板引擎输出
- play framework学习笔记之play tags页面模板
- Java模板引擎之Freemarker 学习笔记 一
- Thymeleaf模板引擎 学习笔记
- laravel学习笔记(5)— Blade模板引擎
- php学习笔记(三十三)php自定义模板引擎的实现
- 模板引擎 NVelocity 初步学习笔记
- sandy引擎学习笔记: 创建一个立方体
- Asp.net控件开发学习笔记(十一)----服务器控件模板
- 软件开发过程学习笔记(五)之测试方案模板
- 设计模式学习笔记--模板方法(Template Method)模式
- Play framework模板引擎
- Django学习笔记1 url、视图和模板
- C++学习笔记-模板
- play framework学习笔记之 使用缓存cache
- C++ Primer 学习笔记_85_模板与泛型编程 -模板特化[续]
- velocity(vm)模板引擎学习介绍及语法
- 【游戏客户端开发】Unity3D 学习笔记2——了解U3D引擎的操作面板和各种工具
- Play framework模板引擎扩展对象JavaExtensions