The following features are supported:
格式如下:
参数必须定义在模板或子模板的开头,在所有的内容开始之前。
#@charset UTF-8
注释可以写在任何地方。如果一个注释从行首开始,或者注释之前没有任何可见字符,则整行将被忽略。
## comment
最简单的写法:
${placeholder}
包含一个或多个参数:
${placeholder: param, param}
可引用一个或多个子模板作为参数。所引用的子模板将从当前子模板或者上级子模板中查找。
${placeholder: #subtpl, #subtpl}
也可引用多级子模板作为参数。
${placeholder: #tpl1.subtpl2.suptpl3}
使用.*可达到引用一组模板的作用。
${placeholder: #tpl1.*}
直接包含一个子模板,不调用visitor。
$#{subtpl}
也可包含多级子模板。
$#{tpl.subtpl1.subtpl2}
子模板必须位于模板或其它子模板的末尾。从最后一行内容到子模板之间的空行将被忽略。子模板可以包含其它子模板。
#subtpl #@trimming on #@whitespace collapse content #end
导入外部文件,作为子模板。这种方法所产生的子模板,和直接定义子模板的效果完全相同。但将子模板定义在外部文件中,有利于整理并缩短模板的长度。
#subtpl(relative_file_name)
或者:
#subtpl("relative_file_name")
A {@code Template} class defines what the generated code should look like.It can accept injected state and use that state to dynamically generate source code. @author Tim Kral
A core FreeMarker API that represents a compiled template. Typically, you will use a {@link Configuration} object to instantiate a template.
Configuration cfg = new Configuration(); ... Template myTemplate = cfg.getTemplate("myTemplate.html");
However, you can also construct a template directly by passing in to the appropriate constructor a java.io.Reader instance that is set to read the raw template text. The compiled template is stored in an an efficient data structure for later use.
To render the template, i.e. to merge it with a data model, and thus produce "cooked" output, call the process method.
Any error messages from exceptions thrown during compilation will be included in the output stream and thrown back to the calling code. To change this behavior, you can install custom exception handlers using {@link Configurable#setTemplateExceptionHandler(TemplateExceptionHandler)} ona Configuration object (for all templates belonging to a configuration) or on a Template object (for a single template).
It's not legal to modify the values of FreeMarker settings: a) while the template is executing; b) if the template object is already accessible from multiple threads. @version $Id: Template.java,v 1.216.2.3 2006/03/10 17:49:02 revusky Exp $
Engine engine = Engine.getEngine(); Template template = engine.getTemplate("/foo.httl");@see httl.Engine#getTemplate(String) @see httl.Engine#getTemplate(String,String) @see httl.Context#getTemplate() @see httl.spi.Translator#translate(Resource,Node,java.util.Map) @author Liang Fei (liangfei0201 AT gmail DOT com)
Like many template systems, the template string is compiled into a program, and then it can be expanded any number of times. For example, in a web app, you can compile the templates once at server startup, and use the expand() method at request handling time. expand() uses the compiled representation.
There are various options for controlling parsing — see {@link TemplateCompiler} and {@link TemplateCompileOptions} Don't go crazywith metacharacters. {}, [], {{}} or <> should cover nearly any circumstance, e.g. generating HTML, CSS XML, JavaScript, C programs, text files, etc.
Template template = Velocity.getTemplate("test.wm"); Context context = new VelocityContext(); context.put("foo", "bar"); context.put("customer", new Customer()); template.merge(context, writer);@author Jason van Zyl @author Geir Magnusson Jr. @version $Id: Template.java,v 1.36.4.1 2004/03/03 22:28:24 geirm Exp $
Clients may instantiate this class. May become final in the future.
@since 3.0 @noextend This class is not intended to be subclassed by clients. Template template = engine.getTemplate("demo.html"); Writer writer = new StringWriter(); template.merge(context, writer); System.out.println(writer.toString());
如果是字符串需要解析: Template template = new Template(engine, "22\n{if 1}\n123\n{/if}\n"); Writer writer = new StringWriter(); template.merge(context, writer); System.out.println(writer.toString());
@see org.lilystudio.smarty4j.Engine
@see org.lilystudio.smarty4j.IParser
@version 1.0.0, 2010/10/01
@author 欧阳先伟
@since Smarty 1.0
Note: All Box Printers used to initialize the page must also have a org.locationtech.udig.printing.ui.boxprinter extension defined for it.
@author Richard GouldTemplate
implemenatation are expected to be thread safe.
@author Uri Boness
A read and parsed template.
Template objects model templates as they are needed by the {@link TemplateEngine}, including its name, {@link TemplateResolution} objects and DOM tree.
@author Daniel Fernández @since 2.0.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|