- 浏览: 1883019 次
- 性别:
- 来自: 合肥
文章分类
- 全部博客 (514)
- OPEN (41)
- WARN (33)
- EXPER (16)
- RESOURCE (7)
- TOOL (4)
- DWR (10)
- Struts1.x (10)
- Ibtais (18)
- MyEclipse (30)
- Sql Server (64)
- Tomcat (7)
- APACHE (4)
- JSP (18)
- SERVLET (6)
- ENGLISH (0)
- ECSide (8)
- JasperReports (7)
- JAVA (24)
- JS (42)
- XML (26)
- CVS (8)
- Mind (1)
- JQUERY (2)
- IBATIS (6)
- PROJECT (0)
- STRUTS2 (0)
- PROXOOL (0)
- SPRING (4)
- Hibernate (0)
- SSI (0)
- JBPM (11)
- FLEX (3)
- JSON (2)
- GWT (1)
- jeecms v3 (1)
- Flash (2)
- DATA (1)
- ORACLE (3)
- 查询oracle 中逗号分隔字符串中所有值 (1)
最新评论
-
小小西芹菜:
GoEasy web三步轻松实现web实时推送1. 引入goe ...
服务器推送技术 java -
kg_1997:
这个方法太棒了,可以不用to_date函数,实在是棒!!!
java/oracle日期处理 -
wodesunday:
:idea:
SQL的分段统计查询语句 -
wodesunday:
引用
SQL的分段统计查询语句 -
BlueSkator:
讲的有点浅,没有深入进去
tomcat需要的重新发布和重启服务器的几种情况
The template at a glance一目了然的模板
Page Contents 网页内容
Intro. 前奏。
Examples of directives 指令的例子
The if directive “if指令
The list directive 该清单指令
The include directive include指令
Using directives together 使用指令一起
Dealing with missing variables 处理缺失变量
The simplest template is a plain HTML file (or whatever text file -- FreeMarker is not confined to HTML).最简单的模板是一个普通的HTML文件(或任何文本文件 - FreeMarker是不局限于HTML)。 When the client visits that page, FreeMarker will send that HTML to the client as is.当客户端访问该页面时,FreeMarker会向客户端发送的HTML。 However if you want that page to be more dynamic then you begin to put special parts into the HTML which will be understood by FreeMarker:然而,如果您希望该网页更加动态的,那么你开始投入将由FreeMarker的理解的HTML特殊部位:
${ ... } : FreeMarker will replace it in the output with the actual value of the thing inside the curly brackets. $ {...}:FreeMarker会在输出取代它与实际值的大括号内的事情。 They are called interpolation s.他们被称为插值号 As an example see the very first example .作为一个例子, 看到的第一个例子。
FTL tags (for FreeMarker Template Language tags): FTL tags are a bit similar to HTML tags, but they are instructions to FreeMarker and will not be printed to the output. FTL标签 (FreeMarker模板语言标记):FTL标签有点类似于HTML标签,但他们对FreeMarker的指令,将不被打印输出。 The name of these tags start with # .这些标记的名称以#开头。 (User-defined FTL tags use @ instead of # , but they are an advanced topic.) (用户自定义FTL标签用@代替#,但他们是一个高级主题。)
Comments: Comments are similar to HTML comments, but they are delimited by <#-- and --> . 评论:是类似于HTML注释的评论,但它们所分隔的<# -和- > 。 Anything between these delimiters and the delimiter itself will be ignored by FreeMarker, and will not be written to the output.之间的分隔符和分隔符本身的东西都会被忽略的FreeMarker将不会被写入到输出。
Anything not an FTL tag or an interpolation or comment is considered as static text, and will not be interpreted by FreeMarker; it is just printed to the output as is.任何FTL标签或插值或意见被认为是为静态文本,并不会被FreeMarker的解释,它只是打印输出。
With FTL tags you refer to so-called directives . FTL标签,你是指所谓的指令。 This is the same kind of relationship as between HTML tags (eg: <table> and </table> ) and HTML elements (eg, the table element) to which you refer to with the HTML tags.这是HTML标签(如:<table>和</ TABLE>)之间的关系的同类和你所提到HTML标记的HTML元素( 例如 ,表元素)。 (If you don't feel this difference then just take "FTL tag" and "directive" as synonyms.) (如果你不觉得这种差异,然后只取“FTL标签”和“指令”作为同义词。)
Examples of directives指令的例子
Though FreeMarker has far more directives, in this quick overview we will only look at three of the most commonly used ones.虽然FreeMarker的指令得多,在这个快速概览,我们只会看看三个最常用的。
The if directive “if指令
With the if directive you can conditionally skip a section of the template.随着if指令,你可以有条件地跳过一段模板。 For example, assume that in the very first example you want to greet your boss, Big Joe, differently from other users:例如,假设在第一个例子中,你要迎接你的老板,大乔,不同于其他用户:
<html> <HTML>
<head> <HEAD>
<title>Welcome!</title> <TITLE>欢迎!</ TITLE>
</head> </ HEAD>
<body> <BODY>
<h1> <H1>
Welcome ${user} <#if user == "Big Joe"> , our beloved leader </#if> !欢迎$ {USER} <#如果用户==“大乔”,我们敬爱的领袖</#如果>!
</h1> </ H1>
<p>Our latest product: <p>我们的最新产品:
<a href="${latestProduct.url}">${latestProduct.name}</a>! <a href="${latestProduct.url}"> $ {latestProduct.name} </ A>!
</body> </ BODY>
</html> </ HTML>
Here you have told FreeMarker that the '', our beloved leader'' should be there only if the value of the variable user is equal to the string "Big Joe" .在这里,你告诉FreeMarker的“,应该是我们敬爱的领袖”,只有当变量用户的值等于字符串“大乔“。 In general, things between <#if condition > and </#if> tags are skipped if condition is false (the boolean value).在一般情况下,事物之间的<#如果条件 >和</>标记#如果被跳过,如果条件为假(布尔值)。
Let's detail the condition used here: The == is an operator that tests if the values at its left and right side are equivalent, and the results is a boolean value, true or false accordingly.让我们详细的条件下使用:==是运营商的测试,如果在其左边和右边的值相等,其结果是一个布尔值,真或假的相应。 On the left side of == I have referenced a variable with the syntax that should be already familiar; this will be replaced with the value of the variable. ==的左边,我引用一个变量的语法应该已经熟悉,这将是变量的值取代。 In general, unquoted words inside directives or interpolations are treated as references to variables.在一般情况下,内部指令或插值加引号的话被视为变量的引用。 On the right side I have specified a literal string.在右边,我指定一个文字字符串。 Literal strings in templates must always be put inside quotation marks.在模板中的文字字符串必须始终放在引号内。
This will print "Pythons are free today!"这将打印“蟒蛇是免费的今天!” if their price is 0:如果他们的价格是0:
<#if animals.python.price == 0 > <#如果animals.python.price == 0>
Pythons are free today!蟒蛇是免费的今天!
</#if> </#“>
Similarly as earlier when a string was specified directly, here a number is specified directly ( 0 ).同样早先直接指定一个字符串时,这里是直接指定(0)。 Note that the number is not quoted.请注意,这一数字是没有报价。 If you quoted it ( "0" ), FreeMarker were misinterpret it as a string literal.如果你引用它(“0”),FreeMarker的被误解为一个字符串常量。
This will print "Pythons are not free today!"这将打印“蟒蛇是不是免费的今天!” if their price is not 0:如果他们的价格是不为0:
<#if animals.python.price != 0> <#如果animals.python.price!= 0>
Pythons are not free today!蟒蛇是不是免费的今天!
</#if> </#“>
As you may have guessed, != means not equivalent.正如您可能已经猜到了,=表示不等于。
You can write things like this too (using the data-model used to demonstrate hashes ):你可以写这样的东西太多(使用的数据模型,用于演示哈希) :
<#if animals.python.price < animals.elephant.price > <#如果animals.python.price <animals.elephant.price>
Pythons are cheaper than elephants today.蟒蛇是比大象更便宜的今天。
</#if> </#“>
With the <#else> tag you can specify what to do if the condition is false.随着其他<#>标记,您可以指定做什么,如果条件为假。 For example:例如:
<#if animals.python.price < animals.elephant.price> <#如果animals.python.price <animals.elephant.price>
Pythons are cheaper than elephants today.蟒蛇是比大象更便宜的今天。
<#else> <其他>
Pythons are not cheaper than elephants today.蟒蛇是不是今天比大象更便宜。
</#if> </#“>
This prints ''Pythons are cheaper than elephants today.'' if the price of python is less than the price of elephant, or else it prints ''Pythons are not cheaper than elephants today.''这将打印“蟒蛇比大象便宜。''如果Python的价格不到大象的价格,否则打印”蟒蛇是不是今天比大象更便宜。
If you have a variable with boolean value (a true/false thing) then you can use it directly as the condition of if :如果你有一个变量,布尔值(真/假的东西),那么你可以直接使用 ,如果条件:
<#if animals.python.protected> <#如果animals.python.protected>
Warning!警告! Pythons are protected animals!蟒蛇是受保护动物!
</#if> </#“>
The list directive该清单指令
This is useful when you want to list something.当你要列出的东西,这是非常有用的。 For example if you merge this template with the data-model I used earlier to demonstrate sequences :例如,如果合并与模板数据模型,我之前使用证明序列:
<p>We have these animals: <table border=1> <tr><th>Name<th>Price <#list animals as being> <tr><td>${ being .name}<td>${ being .price} Euros </#list> </table> <p>我们有这些动物:<table border=1> <TR> <TH>名<TH>价格<TR> <TD> $ {。名称} <TD> $ {<#被列表动物>价格}欧元</列表> </ TABLE>
then the output will be:那么输出将是:
<p>We have these animals: <p>我们有这些动物:
<table border=1> <table border=1>
<tr><th>Name<th>Price <TR> <TH>名<TH>价格
<tr><td>mouse<td>50 Euros <TR> <TD>鼠标<TD> 50欧元
<tr><td>elephant<td>5000 Euros <TR> <TD>大象<TD> 5000欧元
<tr><td>python<td>4999 Euros <TR> <TD>蟒蛇<TD> 4999欧元
</table> </ TABLE>
The generic format of the list directive is: 列表指令的通用格式是:
<#list sequence as loopVariable > repeatThis </#list> <#列表序列loopVariable> repeatThis </#列表>
The repeatThis part will be repeated for each item in the sequence that you have given with sequence , one after the other, starting from the first item. repeatThis部分重复序列中的每个项目,你给带序列,一前一后,从第一项开始。 In all repetitions loopVariable will hold the value of the current item.在所有重复loopVariable将保持当前项的值。 This variable exists only between the <#list ...> and </#list> tags.这个变量之间只存在<#列表...>和</#列表>标记。
As another example, we list the fruits of that example data model:作为另一个例子,我们的清单,例如数据模型的成果:
<p>And BTW we have these fruits: <p>和顺便说一句,我们有以下成果:
<ul> <UL>
<#list whatnot.fruits as fruit> <#列为水果whatnot.fruits>
<li>${fruit} <LI> $ {水果}
</#list> </#列表>
<ul> <UL>
The whatnot.fruits expression should be familiar to you; it references a variable in the data-model . whatnot.fruits表达应该是你熟悉的,它引用了一个数据模型中的变量。
The include directive include指令
With the include directive you can insert the content of another file into the template.随着包括指令,可以插入到模板中的其他文件的内容。
Suppose you have to show the same copyright notice on several pages.假设你有几页上显示的相同的版权声明。 You can create a file that contains the copyright notice only, and insert that file everywhere where you need that copyright notice.您可以创建一个文件,其中包含的版权声明,并到处插入该文件,你需要的版权声明。 Say, you store this copyright notice in copyright_footer.html :说,你存储在copyright_footer.html本版权声明:
<hr> <HR>
<i> <I>
Copyright (c) 2000 <a href="http://www.acmee.com">Acmee Inc</a>,版权所有(c)2000 <a href="http://www.acmee.com"> Acmee公司</ A>,
<br> -
All Rights Reserved.保留所有权利。
</i> </ I>
Whenever you need that file you simply insert it with the include directive:每当你需要的文件,你只需插入 include指令:
<html> <HTML>
<head> <HEAD>
<title>Test page</title> <TITLE>测试页面</ TITLE>
</head> </ HEAD>
<body> <BODY>
<h1>Test page</h1> <H1>测试页</ H1>
<p>Blah blah... <P> BLAH BLAH ...
<#include "/copyright_footer.html"> <#包括“/ copyright_footer.html”>
</body> </ BODY>
</html> </ HTML>
and the output will be:输出将是:
<html> <HTML>
<head> <HEAD>
<title>Test page</title> <TITLE>测试页面</ TITLE>
</head> </ HEAD>
<body> <BODY>
<h1>Test page</h1> <H1>测试页</ H1>
<p>Blah blah... <P> BLAH BLAH ...
<hr> <HR>
<i> <I>
Copyright (c) 2000 <a href="http://www.acmee.com">Acmee Inc</a>, 版权所有(c)2000 <a href="http://www.acmee.com"> Acmee公司</ A>,
<br> -
All Rights Reserved. 保留所有权利。
</i> </ I>
</body> </ BODY>
</html> </ HTML>
If you change the copyright_footer.html , then the visitor will see the new copyright notice on all pages.如果你改变的copyright_footer.html,那么游客将看到在所有网页上的新的版权声明。
Using directives together使用指令一起
You can use directives as many times on a page as you want, and you can nest directives into each other similarly as you can nest HTML elements into each other.只要你想,一个页面上,您可以使用多次指示,并可以巢到对方的指令同样可以嵌套的HTML元素相互转化。 For example this will list the animals and print the name of large animals with bigger font:例如,这将列出动物和大型动物具有更大的字体打印的名称:
<p>We have these animals: <p>我们有这些动物:
<table border=1> <table border=1>
<tr><th>Name<th>Price <TR> <TH>名<TH>价格
<#list animals as being> <#列出的动物 。
<tr> <TR>
<td> <TD>
<#if being.size == "large"> <font size="+1"> </#if> <#如果being.size ==“大”> <font size="+1"> </#如果>
${being.name} $ {being.name}
<#if being.size == "large"> </font> </#if> <#如果being.size ==“大”> </ FONT> </#如果>
<td>${being.price} Euros <TD> $ {being.price}欧元
</#list> </#列表>
</table> </ TABLE>
Note that since FreeMarker does not interpret text outside FTL tags, interpolations and comments, it doesn't see the above font tags as badly nested ones.请注意,因为FreeMarker的不解释FTL标签外,插值和注释的文本,它没有看到上述严重嵌套的字体标记。
Dealing with missing variables处理缺失变量
In practice the data-model often has variables that are optional (ie, sometimes missing).数据模型在实践中,往往已是可选的变量(即,有时会丢失)。 To spot some typical human mistakes, FreeMarker doesn't tolerate the referring to missing variables unless you tell them explicitly what to do if the variable is missing.发现一些典型的人为错误,FreeMarker的不容忍指的是缺少变量,除非你明确告诉他们做什么如果变量是丢失。 Here we will show the two most typical ways of doing that.在这里,我们将展示两个最典型的方式这样做。
Note for programmers: A non-existent variable and a variable with null value is the same for FreeMarker, so the "missing" term used here covers both cases. 程序员注意:一个不存在的变量和一个空值的变量是FreeMarker的相同,所以“失踪”一词用在这里包括两种情况 。
Wherever you refer to a variable, you can specify a default value for the case the variable is missing, by following the variable name with a ! and the default value.无论你是指一个变量,你可以指定一个变量缺失的情况下的默认值,以下!和默认值的变量名。 Like in the following example, when user is missing from data model, the template will behave like if user 's value were the string "Anonymous" .在下面的例子一样,当用户丢失数据模型,该模板将像用户的价值,如果字符串“无名氏”。 (When user isn't missing, this template behaves exactly like if !"Anonymous" were not there): (当用户不缺,这个模板的功能完全一样,如果“无名氏”不存在!):
<h1>Welcome ${user !"Anonymous" }!</h1> <h1>欢迎$ {用户!“无名氏”!} </ H1>
You can ask whether a variable isn't missing by putting ?? after its name.你可以要求通过把一个变量是否是不缺?后它的名字。 Combining this with the already introduced if directive you can skip the whole greeting if the user variable is missing:结合已经出台,如果指令可以跳过整个的问候,如果用户变量缺少这样的:
<#if user?? ><h1>Welcome ${user}!</h1></#if> <#如果用户?> <h1>欢迎$ {USER}!</ H1> </#如果>
Regarding variable accessing with multiple steps, like animals.python.price , writing animals.python.price!0 is correct only if animals.python is never missing and only the last subvariable, price , is possibly missing (in which case here we assume it's 0 ).关于变量与多个步骤, 例如 animals.python.price,访问, 写作animals.python.price 0是正确的只有 animals.python是从来不缺少,只有最后的子变量,价格,可能是缺少(在这种情况下,我们在这里假定它的0)。 If animals or python is missing, the template processing will stop with an "undefined variable" error.如果缺少动物或 Python,模板处理将停 止与“未定义的变量”的错误。 To prevent that, you have to write (animals.python.price)!0 .为了防止这种情况,你必须写(animals.python.price 0)。 In that case the expression will be 0 even if animals or python is missing.在这种情况下,表达式将0动物或 Python,即使丢失。 Same logic goes for ?? ; animals.python.price?? versus (animals.python.price)?? .同样的逻辑??animals.python.price与(animals.python.price)? 。
Next page: Values, Types 下一页:价值型 Previous page 前一页 Parent page 父页 Contents 目录
You are here: Book > Template Author's Guide > Getting Started > The template at a glance 您的位置: 图书 > 模板作者的指南 > 入门 >一目了然模板
FreeMarker Manual -- For FreeMarker 2.3.18 FreeMarker的手册-对于FreeMarker的2.3.18
HTML generated: 2011-05-22 08:01:37 GMT 生成的HTML:2011年5月22日8时01分37秒GMT
英语原文:
The template at a glance
Page Contents 网页内容
Intro. 前奏。
Examples of directives 指令的例子
The if directive “if指令
The list directive 该清单指令
The include directive include指令
Using directives together 使用指令一起
Dealing with missing variables 处理缺失变量
The simplest template is a plain HTML file (or whatever text file -- FreeMarker is not confined to HTML).最简单的模板是一个普通的HTML文件(或任何文本文件 - FreeMarker是不局限于HTML)。 When the client visits that page, FreeMarker will send that HTML to the client as is.当客户端访问该页面时,FreeMarker会向客户端发送的HTML。 However if you want that page to be more dynamic then you begin to put special parts into the HTML which will be understood by FreeMarker:然而,如果您希望该网页更加动态的,那么你开始投入将由FreeMarker的理解的HTML特殊部位:
${ ... } : FreeMarker will replace it in the output with the actual value of the thing inside the curly brackets. $ {...}:FreeMarker会在输出取代它与实际值的大括号内的事情。 They are called interpolation s.他们被称为插值号 As an example see the very first example .作为一个例子, 看到的第一个例子。
FTL tags (for FreeMarker Template Language tags): FTL tags are a bit similar to HTML tags, but they are instructions to FreeMarker and will not be printed to the output. FTL标签 (FreeMarker模板语言标记):FTL标签有点类似于HTML标签,但他们对FreeMarker的指令,将不被打印输出。 The name of these tags start with # .这些标记的名称以#开头。 (User-defined FTL tags use @ instead of # , but they are an advanced topic.) (用户自定义FTL标签用@代替#,但他们是一个高级主题。)
Comments: Comments are similar to HTML comments, but they are delimited by <#-- and --> . 评论:是类似于HTML注释的评论,但它们所分隔的<# -和- > 。 Anything between these delimiters and the delimiter itself will be ignored by FreeMarker, and will not be written to the output.之间的分隔符和分隔符本身的东西都会被忽略的FreeMarker将不会被写入到输出。
Anything not an FTL tag or an interpolation or comment is considered as static text, and will not be interpreted by FreeMarker; it is just printed to the output as is.任何FTL标签或插值或意见被认为是为静态文本,并不会被FreeMarker的解释,它只是打印输出。
With FTL tags you refer to so-called directives . FTL标签,你是指所谓的指令。 This is the same kind of relationship as between HTML tags (eg: <table> and </table> ) and HTML elements (eg, the table element) to which you refer to with the HTML tags.这是HTML标签(如:<table>和</ TABLE>)之间的关系的同类和你所提到HTML标记的HTML元素( 例如 ,表元素)。 (If you don't feel this difference then just take "FTL tag" and "directive" as synonyms.) (如果你不觉得这种差异,然后只取“FTL标签”和“指令”作为同义词。)
Examples of directives指令的例子
Though FreeMarker has far more directives, in this quick overview we will only look at three of the most commonly used ones.虽然FreeMarker的指令得多,在这个快速概览,我们只会看看三个最常用的。
The if directive “if指令
With the if directive you can conditionally skip a section of the template.随着if指令,你可以有条件地跳过一段模板。 For example, assume that in the very first example you want to greet your boss, Big Joe, differently from other users:例如,假设在第一个例子中,你要迎接你的老板,大乔,不同于其他用户:
<html> <HTML>
<head> <HEAD>
<title>Welcome!</title> <TITLE>欢迎!</ TITLE>
</head> </ HEAD>
<body> <BODY>
<h1> <H1>
Welcome ${user} <#if user == "Big Joe"> , our beloved leader </#if> !欢迎$ {USER} <#如果用户==“大乔”,我们敬爱的领袖</#如果>!
</h1> </ H1>
<p>Our latest product: <p>我们的最新产品:
<a href="${latestProduct.url}">${latestProduct.name}</a>! <a href="${latestProduct.url}"> $ {latestProduct.name} </ A>!
</body> </ BODY>
</html> </ HTML>
Here you have told FreeMarker that the '', our beloved leader'' should be there only if the value of the variable user is equal to the string "Big Joe" .在这里,你告诉FreeMarker的“,应该是我们敬爱的领袖”,只有当变量用户的值等于字符串“大乔“。 In general, things between <#if condition > and </#if> tags are skipped if condition is false (the boolean value).在一般情况下,事物之间的<#如果条件 >和</>标记#如果被跳过,如果条件为假(布尔值)。
Let's detail the condition used here: The == is an operator that tests if the values at its left and right side are equivalent, and the results is a boolean value, true or false accordingly.让我们详细的条件下使用:==是运营商的测试,如果在其左边和右边的值相等,其结果是一个布尔值,真或假的相应。 On the left side of == I have referenced a variable with the syntax that should be already familiar; this will be replaced with the value of the variable. ==的左边,我引用一个变量的语法应该已经熟悉,这将是变量的值取代。 In general, unquoted words inside directives or interpolations are treated as references to variables.在一般情况下,内部指令或插值加引号的话被视为变量的引用。 On the right side I have specified a literal string.在右边,我指定一个文字字符串。 Literal strings in templates must always be put inside quotation marks.在模板中的文字字符串必须始终放在引号内。
This will print "Pythons are free today!"这将打印“蟒蛇是免费的今天!” if their price is 0:如果他们的价格是0:
<#if animals.python.price == 0 > <#如果animals.python.price == 0>
Pythons are free today!蟒蛇是免费的今天!
</#if> </#“>
Similarly as earlier when a string was specified directly, here a number is specified directly ( 0 ).同样早先直接指定一个字符串时,这里是直接指定(0)。 Note that the number is not quoted.请注意,这一数字是没有报价。 If you quoted it ( "0" ), FreeMarker were misinterpret it as a string literal.如果你引用它(“0”),FreeMarker的被误解为一个字符串常量。
This will print "Pythons are not free today!"这将打印“蟒蛇是不是免费的今天!” if their price is not 0:如果他们的价格是不为0:
<#if animals.python.price != 0> <#如果animals.python.price!= 0>
Pythons are not free today!蟒蛇是不是免费的今天!
</#if> </#“>
As you may have guessed, != means not equivalent.正如您可能已经猜到了,=表示不等于。
You can write things like this too (using the data-model used to demonstrate hashes ):你可以写这样的东西太多(使用的数据模型,用于演示哈希) :
<#if animals.python.price < animals.elephant.price > <#如果animals.python.price <animals.elephant.price>
Pythons are cheaper than elephants today.蟒蛇是比大象更便宜的今天。
</#if> </#“>
With the <#else> tag you can specify what to do if the condition is false.随着其他<#>标记,您可以指定做什么,如果条件为假。 For example:例如:
<#if animals.python.price < animals.elephant.price> <#如果animals.python.price <animals.elephant.price>
Pythons are cheaper than elephants today.蟒蛇是比大象更便宜的今天。
<#else> <其他>
Pythons are not cheaper than elephants today.蟒蛇是不是今天比大象更便宜。
</#if> </#“>
This prints ''Pythons are cheaper than elephants today.'' if the price of python is less than the price of elephant, or else it prints ''Pythons are not cheaper than elephants today.''这将打印“蟒蛇比大象便宜。''如果Python的价格不到大象的价格,否则打印”蟒蛇是不是今天比大象更便宜。
If you have a variable with boolean value (a true/false thing) then you can use it directly as the condition of if :如果你有一个变量,布尔值(真/假的东西),那么你可以直接使用 ,如果条件:
<#if animals.python.protected> <#如果animals.python.protected>
Warning!警告! Pythons are protected animals!蟒蛇是受保护动物!
</#if> </#“>
The list directive该清单指令
This is useful when you want to list something.当你要列出的东西,这是非常有用的。 For example if you merge this template with the data-model I used earlier to demonstrate sequences :例如,如果合并与模板数据模型,我之前使用证明序列:
<p>We have these animals: <table border=1> <tr><th>Name<th>Price <#list animals as being> <tr><td>${ being .name}<td>${ being .price} Euros </#list> </table> <p>我们有这些动物:<table border=1> <TR> <TH>名<TH>价格<TR> <TD> $ {。名称} <TD> $ {<#被列表动物>价格}欧元</列表> </ TABLE>
then the output will be:那么输出将是:
<p>We have these animals: <p>我们有这些动物:
<table border=1> <table border=1>
<tr><th>Name<th>Price <TR> <TH>名<TH>价格
<tr><td>mouse<td>50 Euros <TR> <TD>鼠标<TD> 50欧元
<tr><td>elephant<td>5000 Euros <TR> <TD>大象<TD> 5000欧元
<tr><td>python<td>4999 Euros <TR> <TD>蟒蛇<TD> 4999欧元
</table> </ TABLE>
The generic format of the list directive is: 列表指令的通用格式是:
<#list sequence as loopVariable > repeatThis </#list> <#列表序列loopVariable> repeatThis </#列表>
The repeatThis part will be repeated for each item in the sequence that you have given with sequence , one after the other, starting from the first item. repeatThis部分重复序列中的每个项目,你给带序列,一前一后,从第一项开始。 In all repetitions loopVariable will hold the value of the current item.在所有重复loopVariable将保持当前项的值。 This variable exists only between the <#list ...> and </#list> tags.这个变量之间只存在<#列表...>和</#列表>标记。
As another example, we list the fruits of that example data model:作为另一个例子,我们的清单,例如数据模型的成果:
<p>And BTW we have these fruits: <p>和顺便说一句,我们有以下成果:
<ul> <UL>
<#list whatnot.fruits as fruit> <#列为水果whatnot.fruits>
<li>${fruit} <LI> $ {水果}
</#list> </#列表>
<ul> <UL>
The whatnot.fruits expression should be familiar to you; it references a variable in the data-model . whatnot.fruits表达应该是你熟悉的,它引用了一个数据模型中的变量。
The include directive include指令
With the include directive you can insert the content of another file into the template.随着包括指令,可以插入到模板中的其他文件的内容。
Suppose you have to show the same copyright notice on several pages.假设你有几页上显示的相同的版权声明。 You can create a file that contains the copyright notice only, and insert that file everywhere where you need that copyright notice.您可以创建一个文件,其中包含的版权声明,并到处插入该文件,你需要的版权声明。 Say, you store this copyright notice in copyright_footer.html :说,你存储在copyright_footer.html本版权声明:
<hr> <HR>
<i> <I>
Copyright (c) 2000 <a href="http://www.acmee.com">Acmee Inc</a>,版权所有(c)2000 <a href="http://www.acmee.com"> Acmee公司</ A>,
<br> -
All Rights Reserved.保留所有权利。
</i> </ I>
Whenever you need that file you simply insert it with the include directive:每当你需要的文件,你只需插入 include指令:
<html> <HTML>
<head> <HEAD>
<title>Test page</title> <TITLE>测试页面</ TITLE>
</head> </ HEAD>
<body> <BODY>
<h1>Test page</h1> <H1>测试页</ H1>
<p>Blah blah... <P> BLAH BLAH ...
<#include "/copyright_footer.html"> <#包括“/ copyright_footer.html”>
</body> </ BODY>
</html> </ HTML>
and the output will be:输出将是:
<html> <HTML>
<head> <HEAD>
<title>Test page</title> <TITLE>测试页面</ TITLE>
</head> </ HEAD>
<body> <BODY>
<h1>Test page</h1> <H1>测试页</ H1>
<p>Blah blah... <P> BLAH BLAH ...
<hr> <HR>
<i> <I>
Copyright (c) 2000 <a href="http://www.acmee.com">Acmee Inc</a>, 版权所有(c)2000 <a href="http://www.acmee.com"> Acmee公司</ A>,
<br> -
All Rights Reserved. 保留所有权利。
</i> </ I>
</body> </ BODY>
</html> </ HTML>
If you change the copyright_footer.html , then the visitor will see the new copyright notice on all pages.如果你改变的copyright_footer.html,那么游客将看到在所有网页上的新的版权声明。
Using directives together使用指令一起
You can use directives as many times on a page as you want, and you can nest directives into each other similarly as you can nest HTML elements into each other.只要你想,一个页面上,您可以使用多次指示,并可以巢到对方的指令同样可以嵌套的HTML元素相互转化。 For example this will list the animals and print the name of large animals with bigger font:例如,这将列出动物和大型动物具有更大的字体打印的名称:
<p>We have these animals: <p>我们有这些动物:
<table border=1> <table border=1>
<tr><th>Name<th>Price <TR> <TH>名<TH>价格
<#list animals as being> <#列出的动物 。
<tr> <TR>
<td> <TD>
<#if being.size == "large"> <font size="+1"> </#if> <#如果being.size ==“大”> <font size="+1"> </#如果>
${being.name} $ {being.name}
<#if being.size == "large"> </font> </#if> <#如果being.size ==“大”> </ FONT> </#如果>
<td>${being.price} Euros <TD> $ {being.price}欧元
</#list> </#列表>
</table> </ TABLE>
Note that since FreeMarker does not interpret text outside FTL tags, interpolations and comments, it doesn't see the above font tags as badly nested ones.请注意,因为FreeMarker的不解释FTL标签外,插值和注释的文本,它没有看到上述严重嵌套的字体标记。
Dealing with missing variables处理缺失变量
In practice the data-model often has variables that are optional (ie, sometimes missing).数据模型在实践中,往往已是可选的变量(即,有时会丢失)。 To spot some typical human mistakes, FreeMarker doesn't tolerate the referring to missing variables unless you tell them explicitly what to do if the variable is missing.发现一些典型的人为错误,FreeMarker的不容忍指的是缺少变量,除非你明确告诉他们做什么如果变量是丢失。 Here we will show the two most typical ways of doing that.在这里,我们将展示两个最典型的方式这样做。
Note for programmers: A non-existent variable and a variable with null value is the same for FreeMarker, so the "missing" term used here covers both cases. 程序员注意:一个不存在的变量和一个空值的变量是FreeMarker的相同,所以“失踪”一词用在这里包括两种情况 。
Wherever you refer to a variable, you can specify a default value for the case the variable is missing, by following the variable name with a ! and the default value.无论你是指一个变量,你可以指定一个变量缺失的情况下的默认值,以下!和默认值的变量名。 Like in the following example, when user is missing from data model, the template will behave like if user 's value were the string "Anonymous" .在下面的例子一样,当用户丢失数据模型,该模板将像用户的价值,如果字符串“无名氏”。 (When user isn't missing, this template behaves exactly like if !"Anonymous" were not there): (当用户不缺,这个模板的功能完全一样,如果“无名氏”不存在!):
<h1>Welcome ${user !"Anonymous" }!</h1> <h1>欢迎$ {用户!“无名氏”!} </ H1>
You can ask whether a variable isn't missing by putting ?? after its name.你可以要求通过把一个变量是否是不缺?后它的名字。 Combining this with the already introduced if directive you can skip the whole greeting if the user variable is missing:结合已经出台,如果指令可以跳过整个的问候,如果用户变量缺少这样的:
<#if user?? ><h1>Welcome ${user}!</h1></#if> <#如果用户?> <h1>欢迎$ {USER}!</ H1> </#如果>
Regarding variable accessing with multiple steps, like animals.python.price , writing animals.python.price!0 is correct only if animals.python is never missing and only the last subvariable, price , is possibly missing (in which case here we assume it's 0 ).关于变量与多个步骤, 例如 animals.python.price,访问, 写作animals.python.price 0是正确的只有 animals.python是从来不缺少,只有最后的子变量,价格,可能是缺少(在这种情况下,我们在这里假定它的0)。 If animals or python is missing, the template processing will stop with an "undefined variable" error.如果缺少动物或 Python,模板处理将停 止与“未定义的变量”的错误。 To prevent that, you have to write (animals.python.price)!0 .为了防止这种情况,你必须写(animals.python.price 0)。 In that case the expression will be 0 even if animals or python is missing.在这种情况下,表达式将0动物或 Python,即使丢失。 Same logic goes for ?? ; animals.python.price?? versus (animals.python.price)?? .同样的逻辑??animals.python.price与(animals.python.price)? 。
Next page: Values, Types 下一页:价值型 Previous page 前一页 Parent page 父页 Contents 目录
You are here: Book > Template Author's Guide > Getting Started > The template at a glance 您的位置: 图书 > 模板作者的指南 > 入门 >一目了然模板
FreeMarker Manual -- For FreeMarker 2.3.18 FreeMarker的手册-对于FreeMarker的2.3.18
HTML generated: 2011-05-22 08:01:37 GMT 生成的HTML:2011年5月22日8时01分37秒GMT
英语原文:
The template at a glance
发表评论
-
Apache FileUpload组件
2013-11-22 15:05 5450Apache FileUpload组件 在最初的 htt ... -
各种数据库对应的jar包、驱动类名和URL格式
2012-11-20 16:38 1515各种数据库对应的jar包、驱动类名和URL格式 2011 ... -
Java Web Start
2011-09-14 10:45 1351一.首先了解一下什么是java web start 1JNL ... -
FreeMarker
2011-08-05 09:04 1130一目了然的数据模型 As you have seen, th ... -
jeecms v3
2011-07-04 15:28 1571好久没有逛jeecms的官方论坛了,今天去看了下,jeecms ... -
gwt整合ibatis
2011-07-02 09:42 2084最近整合gwt整合ibatis,常见错误 控制台报错: 一.N ... -
GWT RPC原理浅析(二)
2011-06-17 16:14 2857前一篇介绍了RPC大体的流程,核心方法是RemoteServi ... -
GWT RPC原理浅析
2011-06-17 15:26 5331GWT中前后台交互有多种方式,包括JSON,XML,RPC 其 ... -
五种开源协议
2011-04-25 14:54 1118五种开源协议(BSD,Apache,G ... -
JAVA代码调用客户端摄像头 初步探讨
2011-02-21 16:51 6760首先到sun下载最新的jmf,然后安装。 然后,说一下 ... -
tomcat部署jbpm项目 loader constraint violation
2011-02-11 14:22 1804当tomcat部署jbpm项目 时,启动项目控制台出错 ja ... -
E3.Tree参考手册
2010-12-10 09:52 3585E3.Tree参考手册 (v1.0) 目录 简介 2 系统 ... -
e3.tree 1.5 发布,很好,很强大,有截图[转]
2010-12-07 14:14 1143E3.Tree是E3平台下一个用于构造树型UI(menu,tr ... -
在Action中获取ServletContext实例
2010-11-25 13:43 37691:在Action中获取servletContext的时候可以 ... -
Bean named 'sqlMapClient' must be of type [org.springframework.orm.ibatis.SqlMap
2010-11-22 09:57 4945在整合spring2.5和ibatis2,出现了ibatis的 ... -
spring,ibatis的笔记
2010-11-22 08:51 1045在上文中,我们把iface ... -
spring,ibatis的笔记
2010-11-22 08:51 977在上文中,我们把iface ... -
后台错误处理
2010-11-17 15:10 1329后台处理 if (!isTokenValid(request) ... -
struts1 和Spring整合jar包
2010-11-17 11:33 5016struts1 和Spring整合 struts1 和Spri ... -
spring 与struts的集成
2010-11-17 08:37 1282Struts与Spring的集成主要有两种方式,即Delega ...
相关推荐
MAYA at a glance by George Maestri SYBEX
"CMMI-V2.0-Model-at-a-Glance-english.pdf" CMMI(Capability Maturity Model Integration,能力成熟度模型集成)是一种成熟度模型,旨在帮助组织提高业务性能和能力。CMMI V2.0 是一种集成的产品套件,包括多个...
JavaTM SE 6 Platform at a Glance
### ITIL Version 3 关键知识点概述 #### 引言 ITIL(Information Technology Infrastructure Library)版本3,作为一套指导IT服务管理的最佳实践框架,在全球范围内被广泛采用。本参考指南旨在提供一个全面且易于...
CMMI(Capability Maturity Model Integration,能力成熟度模型集成)是软件开发和组织改进领域的一个重要框架,它提供了一套结构化的最佳实践,旨在帮助组织提升其业务绩效和过程能力。CMMI V2.0是该模型的最新版本...
标题“svcc-at-a-glance-zht.rar”表明这是一个关于SVCC(可能是Service Virtualization and Cloud Computing,服务虚拟化与云计算)的中文概览文件,压缩格式为RAR,通常用于打包和分享多个文件。描述中同样提及...
【标题】"svcc-at-a-glance-zht (1).rar" 提供的是一份关于SVCC(可能是“Service Virtualization and Cloud Computing”或“System V for C++”的缩写,具体含义需要根据上下文确认)的概览资料,这份资料是中文版...
带有“概览”小部件和背景中的“地球视图”墙纸,可为新标签添加新外观。 “概览”功能通过“概览”小部件和背景中的“地球视图”墙纸为您的新标签添加了新的外观。 小部件显示您所在地区的当前日期和天气。...
Week 1 at a Glance Day 1 Getting Started Day 2 The Parts of a C++ Program Day 3 Variables and Constants Day 4 Expressions and Statements Day 5 Functions Day 6 Basic Classes Day 7 More ...
《波兰层专家顾问系统——MetaTrader 4 EA的高效运用》 在外汇交易的世界中,自动化交易策略成为了许多投资者的首选。"波兰层专家顾问系统(Polish Layer Expert Advisor System Efficient - PLEASE)"是一个专为...
A_Glance_at_RSA_Conference_2014.pdf
语言:English reddit一目了然显示在弹出窗口中的reddit posts,并通知您的新帖子 沉迷于reddit? 不断检查新帖子的前页,只能找出任何改变的... 结帐源代码在此处:https://github.com/stefaluc/reddit-at-a-vlance
Bombardier的《Brand Guidelines_at_a_Glance》提供了详细的品牌身份指导原则,帮助员工和合作伙伴理解并遵循其品牌理念和视觉规范。 Bombardier,作为一个全球知名的企业,专注于创新移动解决方案,通过火车和...
13. **At a glance**: 一眼看去,如:She recognized him at a glance. 14. **At a guess**: 猜测,估计,如:The room probably measures 20 square meters at a guess. 15. **At a loose end**: 无所事事,不知道...
Reddit一览显示在一个弹出窗口中的分享帖子,并通知您新的职位 沉迷于reddit? 不断检查首页是否有新帖子,只是发现没有任何...在此处签出源代码:https://github.com/stefaluc/reddit-at-a-glance 支持语言:English
Glance是OpenStack云平台中的一个关键组件,主要负责镜像服务,为虚拟机实例提供镜像的存储、检索和管理功能。以下是对Glance安装配置的详细说明: 1. **创建Glance数据库及授权** 在安装Glance之前,需要在MySQL...
Glance是OpenStack云平台中的一个关键组件,主要负责提供虚拟机镜像的存储和检索服务。在"glance 1.1"这个版本中,我们聚焦于OpenStack Glance的早期发展,它为OpenStack生态系统奠定了基础。下面将详细讨论Glance ...
QTP At Glance 完整的HP官方资料,基础和高级各2个PPT. 推荐,无论新手还是有使用经验的
LoadRunner At Glance 3个PPT文件,全面介绍了Vugen,Controller,Analysis三个主要部分的使用。