freemarker

Remove HTML tags in Freemarker Template

旧街凉风 提交于 2019-12-02 04:21:24
I've got a freemarker template that displays the same string in a context where HTML is allowed as well as a context where it is not. Is there a built-in in Freemarker that allows me to entirely remove HTML tags from a string? The following template (assuming there was a built-in remove_html ) <#ftl output_format="HTML"/> <html> <head> <title>${page_title?remove_html}</title> </head> <body> <h1>${page_title?no_esc}</h1> </body> </html> and the model Collections.singletonMap("page_title", "A <strong>Strong</strong> Argument") should lead to <html> <head> <title>A Strong Argument</title> </head>

freemarkers skip assertNonNull InvalidReferenceException

蹲街弑〆低调 提交于 2019-12-02 03:48:30
I render a list of Objects with freemarker: <ul> <#list publication as item> <li><b>${item.key}</b> : ${item.value}</li> </#list> </ul> but some of the item have a item.value null that raises the exception: freemarker.core.InvalidReferenceException: Expression item.value is undefined on line 12, column 44 in mailTemplate. at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125) at freemarker.core.Expression.getStringValue(Expression.java:118) I would like that freemarker renders "null" or nothing and keeps sending the mail instead of blocking on that I can always check the list

Dynamic Freemarker variable name

本小妞迷上赌 提交于 2019-12-02 03:39:39
问题 I'm trying to set a variable with a dynamic name. This means the name for my new variable comes from another variable: <#-- in real world I wouldn't declare this variables right here - they would come from somewhere else --> <#assign varName = "myVarName"/> <#assign varValue = "myVarValue/> <#... set the variable .../> So that the value can be referenced as follows: ${myVarName} <#-- prints "myVarValue" --> In a Java directive I would use Environment#setVariable(String name, TemplateModel

Disable freemarker logs

纵然是瞬间 提交于 2019-12-02 02:17:35
I'm using Struts 2.0.11.2 and I don't what was changed recently in my app that I get TONS of freemarker logs: DEBUG 13201 [freemark] (): template/simple/hidden.ftl[en,UTF-8,parsed] cached copy not yet stale; using cached. How can I turn off these annoying logs? I know of the freemarker.properties file but I don't find how to specify log levels from there. I tried the hack in my code: freemarker.log.Logger.selectLoggerLibrary(freemarker.log.Logger.LIBRARY_NONE); and for some people it doesn't work. I'm not using log4j, just standard java logging. By the way: I'm not planning to change the

get value of the string stored in a variable, whose name stored as string in another variable

别说谁变了你拦得住时间么 提交于 2019-12-02 00:37:40
问题 <#assign blah = "foo"> <#assign foo = "awesome"> Can we render "awesome" without referencing foo ? I tried something like ${${blah}} But it isn't working, any ideas ? 回答1: There is an eval built-in which evaluates a string as an FTL expression. In your case use it like this: ${blah?eval} 来源: https://stackoverflow.com/questions/21276930/get-value-of-the-string-stored-in-a-variable-whose-name-stored-as-string-in-ano

Eclipse安装Freemarker Editor插件

五迷三道 提交于 2019-12-01 21:16:41
Eclipse安装Freemarker Editor插件 在下面网址里下载freemarker-ide: http://sourceforge.net/projects/freemarker-ide/files/ http://sourceforge.net/projects/freemarker-ide/files/ 下载完成后后解压,由于该IDE里面的freemarker版本较老,需要将现有(自己用的)版本的freemarker.jar替代原来的freemarker-2.3.6.jar,并修改: /META-INF/MANIFEST.MF /META-INF/MANIFEST.MF 将Bundle-ClassPath: freemarker-2.3.6.jar,中的freemarker的jar替换成自己的。然后将解压后的plugin文件夹下的hudson.freemarker_ide_0.9.14包,复制到eclispe的plugin文件夹下,重启eclipse,可以看到.ftl格式文件已经设置为默认freemarker editor编辑了。 PS:有些ftl模板是写在.html,.htm格式的文件中,为了在开发这些文件时也能够识别ftl变量,需要为这些文件添加打开方式: 在window –> Preferences 左边的树形栏里出现FreeMarker

Tiny模板引擎(Velocity Plus)应用示例

こ雲淡風輕ζ 提交于 2019-12-01 19:49:48
把TinyTemplate当成是Velocity的升级版其实也是可以的,毕竟它的语法是基到Veloccity扩展而来的,兼容度在80%以上。 至于TinyTemplate的实例是怎样的,且看下面: 宏的可变参数 在Java中的可变参数使用起来非常方便,Tiny模板也对可变参有一定支持。 #macro hello() ParameterList: ${helloParameterList.size()} #for(para:helloParameterList) hello:${para} #end #end #call("hello","aa",1,true,false) 运行结果: ParameterList: 4 hello:aa hello:1 hello:true hello:false 说明:在宏的包体中,有一个默认的变量,名称就是宏的名字+ParameterList,当前例子中,宏的名字是hello,所以变量的名字就是:helloParameterList。 此变量的类似是一个List,因此可以调用List的方法。 Set示例 运行结果: 宏定义及其调用示例 1:1 2:2 3:1 4:2 5:2 解释: 首先设置abc=1,然后显示它的值,结果是1,这个是理所当然的。 然后定义一个宏,在宏里设置变量abc的值为2,然后显示这个值。 在调用setAbc宏的时候

Spring-Boot with JSP Tag Libs in embedded Tomcat

天涯浪子 提交于 2019-12-01 19:22:52
问题 I am currently migrating a Spring MVC Webapp (xml-config to java-config, tomcat to embedded tomcat via spring-boot). The webapp uses freemarker as templating engine and JSP Taglibs. Now when I call a freemarker page I get the following error: freemarker.ext.jsp.TaglibFactory$TaglibGettingException: No TLD was found for the "http://www.springframework.org/tags/form" JSP taglib URI. (TLD-s are searched according the JSP 2.2 specification. In development- and embedded-servlet-container setups

How to convert date in specific format in Freemarker template or javascript

耗尽温柔 提交于 2019-12-01 19:02:31
From json, i am getting the value as "createdOn": "Jan 08 2015 20:40:56 GMT+0530 (IST)", I am Accessing in FTL <#list variables as variable> <div class="reply"> ${variable.createdOn} </div> </#list> The result i am getting is Jan 09 2015 12:36:18 GMT+0530 (IST) My preferable format is 09-01-2015 I need to remove rest of the time GMT, IST and so on. How to convert this in Freemarker template or javascript. Update I tried to pass below like this ${variable.createdOn?datetime?string("dd-MM-yyyy")} but it is giving error as Exception: java.text.ParseException - Unparseable date: "Jan 09 2015 12:36

Java.time (Java 8) support in Freemarker

半世苍凉 提交于 2019-12-01 18:00:57
Does anybody know of any plans to support the new java.time api in FreeMarker? Or has anybody code laying around for supporting classes like ZonedDateTime, LocalDateTime and Instant? Its not hard to see how to implement these things myself, but it is actually a rather big task. Let's assume that you want format new date/time objects Create custom method: public static class FormatDateTimeMethodModel implements TemplateMethodModelEx { public Object exec(List args) throws TemplateModelException { if (args.size() != 2) { throw new TemplateModelException("Wrong arguments"); } TemporalAccessor time