freemarker

Is there a way to do gsp partials rather than tag libraries?

こ雲淡風輕ζ 提交于 2019-12-10 21:43:53
问题 One of the things I liked about freemarker is that you can quickly create new macros that encapsulate complex html to make the pages smaller and more concise. Do I have to make tag libraries to do the same thing in grails, or is there a really light-weight syntax for achieving the same thing? 回答1: There is a <g:render> tag, which may match your needs. It's documented here. 来源: https://stackoverflow.com/questions/2903353/is-there-a-way-to-do-gsp-partials-rather-than-tag-libraries

freemarker的if else

笑着哭i 提交于 2019-12-10 20:08:23
1. user对象可能为空 <#if user??>   //不为空处理 <#else>   //空处理 <#if>    2. user对象和name属性都可能为空 <#if (user.name)??>   //不为空处理 <#else>   //空处理 <#if> 来源: https://www.cnblogs.com/TulipsWill/p/12018823.html

Unable to render date from model template

只谈情不闲聊 提交于 2019-12-10 20:07:48
问题 I'm working on a Grails project with Freemarker and am having trouble rendering a date from the data model. I start put placing a date into the model def dataModel = [:] def dataDate = new Date().parse("yyyy-MM-dd","2015-08-20") dataModel.put("someDate",dataDate) I then loop through the dataModel to verify the data types dataModel.each { name, value -> println "${name} : ${value} (Value is type: ${value.getClass()})" } For this my output is: someDate : Thu Aug 20 00:00:00 CDT 2015 (Value is

How do I calculate the difference in days between two ISO8601 dates with Freemarker?

余生颓废 提交于 2019-12-10 18:37:11
问题 I have an object in Freemarker which has dates in ISO8601 format (e.g. 2012-02-01T13:01:02+0000 ), how would I go about working out the difference in days between it and now? In other non-Java scenarios I'd reformat it as a unix timestamp and do the maths (like the distance_of_time_in_words functions in RoR or Symfony), however as far as I can see, Freemarker is unable to turn a ISO8601 timestamp into unix timestamp. And yes, I realise the template layer probably isn't the right place to be

Inheritance / instanceof checks in Freemarker

我的梦境 提交于 2019-12-10 18:09:29
问题 my use case is to provide the user the possibility to create reports with the help of a template engine. Therefore I extracted the relevant part of my data model and integrated Freemarker as template engine. So far it worked great, but now my data model contains inheritance on some positions - but Freemarker does not seem to support instanceof operations? How to deal with this problem? Are there any other template engines which support inheritance in the model? Fictive example: I have 2

FREEMARKER: avoid escaping HTML chars

一曲冷凌霜 提交于 2019-12-10 17:41:45
问题 Having a problem with freemarker output... [#assign optionsHTML = ""] [#list data as item] [#assign optionsHTML = optionsHTML + '<option value="' + item.value +'>'+ item.label + '</option>' /] [/#list] so, if I do <select> ${iptionsHTML} </select> the output from otions get html entities instead of actual html.... so <option value=&quot ..... even if I do [#assign optionsHTML = ""] [#list data as item] [#noescape] [#assign optionsHTML = optionsHTML + '<option value="' + item.value +'>'+ item

Accessing properties of Objects within <#list>

冷暖自知 提交于 2019-12-10 14:58:02
问题 Solution I had previously tried adding accessors to the LineItem class like public String getItemNo() { return itemNo; } and changing the FTL from ${lineItem.itemNo} to ${lineItem.getItemNo()} but that didn't work. Solution was to add the accessors but not change the FTL (keep it as ${lineItem.itemNo} . Background I'm using Freemarker to format some emails. In this email I am required to list a number of lines of product information like on an invoice. My goal is to pass a list of Objects

Freemarker syntax for a form for a collection of objects (Spring 3 MVC)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 14:42:40
问题 I have a command bean ( FooList ) which has a property which is a collection (a List of Foo beans). I'm trying to create a form which can edit all the Foo s at once. I have found many examples of how to do this using JSP, but I'm having trouble translating these to Freemarker syntax. In my Freemarker template, I can easily iterate over the collection: [#list fooList.foos as foo] ... [/#list] I can also refer to a particular Foo by index: [@spring.bind "fooList.foos[0].name" /] <input type=

spring boot(一)

删除回忆录丶 提交于 2019-12-10 14:31:26
freemarker: freemarker所需要依赖: <!-- 添加freemarker模版的依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> application.properties中freemarker的配置: ## Freemarker 配置 spring.freemarker.template-loader-path=classpath:/templates/ spring.freemarker.cache=false spring.freemarker.suffix=.ftl spring.freemarker.charset=UTF-8 spring.freemarker.check-template-location=true spring.freemarker.content-type=text/html spring.freemarker.expose-request-attributes=false spring.freemarker.expose-session-attributes=false spring.freemarker

SpringBoot使用freemarker

天大地大妈咪最大 提交于 2019-12-10 13:54:04
导入依赖 <!-- 添加freemarker模版的依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> application.properties文件中新增freemarker配置 ## Freemarker 配置 spring.freemarker.template-loader-path=classpath:/templates/ spring.freemarker.cache=false spring.freemarker.charset=UTF-8 spring.freemarker.check-template-location=true spring.freemarker.content-type=text/html spring.freemarker.expose-request-attributes=false spring.freemarker.expose-session-attributes=false spring.freemarker.request-context-attribute=request spring.freemarker