Cheetah是python的模板框架. 成熟度和效率都很不错.
嵌套
下面记录一些使用Cheetah进行web开发的常用语句.
变量替代
- 我的名字叫 $name
- $staff.address.roadname
- #如果混合...
- 他是个${desease}患者.
- #两个变量在一起也可以.
- $foo$bar
if判断
else是可选的:
- #if $keywords
- $keywords
- #else
- There are no keywords!
- #end if
- #if $keywords
- <span class=keywords>$keywords</span>
- #end if
循环
- #for $author in $authors
- $author.person.fullName
- #end for
文件包含
- $name
- <p> $content
- #include "authors.html"
嵌套
(接上例)
- #if $authors
- <table class=Author>
- #for $author in $authors
- <tr class=Author> <td class=Author>
- $author
- </td> </tr>
- #end for
- </table>
- #end if
#slurp
- #set sep = ''
- #for $author in $authors
- ${sep}${author.person}#slurp
- #set sep = ', '
- #end for