freemarker中文手册(2)

2019-09-01 13:28

| +- animals | | | +- mouse | | | | | +- size = \ | | | | | +- price = 50 | | | +- elephant | | | | | +- size = \ | | | | | +- price = 5000 | | | +- python | | | +- size = \ | | | +- price = 4999 | +- test = \ | +- whatnot | +- because = \? 类似于目录的变量称为hashes,包含保存下级变量的唯一的查询名字 ? 类似于文件的变量称为scalars,保存单值

? scalars保存的值有两种类型:字符串(用引号括起,可以是单引号或双引号)

和数字(不要用引号将数字括起,这会作为字符串处理) ? 对scalars的访问从root开始,各部分用“.”分隔,如animals.mouse.price ? 另外一种变量是sequences,和hashes类似,只是不使用变量名字,而使用数字

索引,如下面的例子:

(root) | +- animals | | | +- (1st) | | | | | +- name = \ | | | | | +- size = \ | | | | | +- price = 50 | | | +- (2nd) | | | | | +- name = \ | | | | | +- size = \ | | | | | +- price = 5000 | | | +- (3rd) | | | +- name = \ | | | +- size = \ | | | +- price = 4999 | +- whatnot | +- fruits | +- (1st) = \ | +- (2nd) = \? 这种对scalars的访问使用索引,如animals[0].name (3)模板

? 在FreeMarker模板中可以包括下面三种特定部分:

? ${…}:称为interpolations,FreeMarker会在输出时用实际值进行替代 ? FTL标记(FreeMarker模板语言标记):类似于HTML标记,为了与HTML标记区分,用#开始(有些以@开始,在后面叙述) ? 注释:包含在<#--和-->(而不是)之间 ? 下面是一些使用指令的例子:

? if指令

<#if animals.python.price < animals.elephant.price> Pythons are cheaper than elephants today. <#else> Pythons are not cheaper than elephants today. ? list指令

We have these animals: NamePrice <#list animals as being> ${being.name}${being.price} Euros 输出为:

We have these animals: NamePrice mouse50 Euros elephant5000 Euros python4999 Euros ? include指令 Test page

Test page

Blah blah... <#include \ ? 一起使用指令

We have these animals: NamePrice <#list animals as being> <#if being.size = \ ${being.name} <#if being.size = \ ${being.price} Euros FreeMarker设计指南(3) 3、模板

(1)整体结构

? 模板使用FTL(FreeMarker模板语言)编写,是下面各部分的一个组合:

? 文本:直接输出

? Interpolation:由${和},或#{和}来限定,计算值替代输出

? FTL标记:FreeMarker指令,和HTML标记类似,名字前加#予以区分,不会

输出

? 注释:由<#--和-->限定,不会输出 ? 下面是以一个具体模板例子:

[BR] [BR] Welcome![BR] [BR] [BR] <#-- Greet the user with his/her name -->[BR]

Welcome ${user}!

[BR]

We have these animals:[BR] [BR] <#list animals as being>[BR] ${being.name} for ${being.price} Euros[BR] [BR] [BR] [BR]

? [BR]是用于换行的特殊字符序列 ? 注意事项:

? FTL区分大小写,所以list是正确的FTL指令,而List不是;${name}和

${NAME}是不同的

? Interpolation只能在文本中使用

? FTL标记不能位于另一个FTL标记内部,例如:

<#if <#include 'foo'>='bar'>... ? 注释可以位于FTL标记和Interpolation内部,如下面的例子:

Welcome ${user <#-- The name of user -->}!

[BR]


freemarker中文手册(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:湖北蓝田股份有限公司财务报表分析

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: