doubt that什么意思:play framework学习笔记之 模板引擎

来源:百度文库 编辑:偶看新闻 时间:2024/04/19 06:28:50

play framework学习笔记之 模板引擎

分类: play framework 2011-04-17 16:57 70人阅读 评论(0) 收藏 举报

模板语法

${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' }   循环

  • ${account}
  • #{/list}

     

     

     

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

    All accounts 

     

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

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

    @{…}相对路径

     

    @@{…}绝对路径

     

     

    Messages: &{…}

     

     

     

     

     

    比如  conf/messages 文件里

     

    clientName=The client name is %s

     

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

     

    &{'clientName','myname' }

    得到的结果是  

    The client name is myname

     

     

     

    Comment: *{…}*  注释

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

     

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

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

    Client ${fullName}

     

     

     

    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 /}