Freemaker - 入门+深入+开发指南+学习笔记(7)

2019-01-26 13:26

Welcome!

Welcome Big Joe!

Our latest product:

(2)数据模型

l 典型的数据模型是树型结构,可以任意复杂和深层次,如下面的例子: (root) |

+- animals | |

| +- mouse | | |

| | +- size = \ | | |

| | +- price = 50 | |

| +- elephant | | |

31

| | +- size = \ | | |

| | +- price = 5000 | |

| +- python | |

| +- size = \ | |

| +- price = 4999 |

+- test = \ |

+- whatnot |

+- because = \

l 类似于目录的变量称为hashes,包含保存下级变量的唯一的查询名字 l 类似于文件的变量称为scalars,保存单值

l scalars保存的值有两种类型:字符串(用引号括起,可以是单引号或双引号)和数字(不要用引号将数字括起,这会作为字符串处理)

l 对scalars的访问从root开始,各部分用“.”分隔,如animals.mouse.price l 另外一种变量是sequences,和hashes类似,只是不使用变量名字,而使用数字索引,如下面的例子:

32

(root) |

+- animals | | | +- (1st) | | |

| | +- name = \ | | |

| | +- size = \ | | |

| | +- price = 50 | | | +- (2nd) | | |

| | +- name = \ | | |

| | +- size = \ | | |

| | +- price = 5000 | | | +- (3rd) | |

33

| +- name = \ | |

| +- size = \ | |

| +- price = 4999 |

+- whatnot | +- fruits |

+- (1st) = \ |

+- (2nd) = \

l 这种对scalars的访问使用索引,如animals[0].name (3)模板

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

? ${…}:称为interpolations,FreeMarker会在输出时用实际值进行替代

? FTL标记(FreeMarker模板语言标记):类似于HTML标记,为了与HTML标记区分,用#开始(有些以@开始,在后面叙述)

? 注释:包含在<#--和-->(而不是)之间 l 下面是一些使用指令的例子: ? if指令

34

<#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指令

35


Freemaker - 入门+深入+开发指南+学习笔记(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:冀教版小学一年级数学上册《10的组成和分解》教学设计

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

马上注册会员

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