freemarker

Can I change the default variable delimiter in Freemarker?

I am working on a project where I am generating some code/scripts (specifically Perl scripts) via Java and Freemarker. I have it working for now, but was wondering if there was some way to change the default variable delimiter ($) in Freemarker? Or is there a different Java template engine that would use a variable delimiter more suita...

Spring 3 and a custom object wrapper for FreeMarker

How do you configure Spring 3 to use a custom object wrapper to use with FreeMarker? I've created a custom object wrapper for FreeMarker but I'm not sure how you configure Spring 3 to use the wrapper. The following has no effect: <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarker...

Freemarker hash for Struts2 @s.select tag's list property

I'm using Freemarker as the templating engine for a Struts 2 application and having some problems trying to pass a Freemarker hash to the @s.select tag's list value. Currently I'm trying something like this in my template: <@s.select name="myDropdown" list={"1":"Foo", "2":"Bar", 3:"Baz"} /> The resulting HTML that's rendered is this:...

How to display the current month in FTL code?

How can I print the current month in a ftl file? ...

Ignoring all line feeds in a FreeMarker template

I'm trying out FreeMarker, not for a web application but to generate text within a desktop application. I'd like to get the text without any linefeeds, however it always appends a linefeed. For example, this would produce "blah blah\n" <#if docType=1> blah blah <#if docType=2> more blah <#/if> Any ideas? Bunching it all into one line...

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

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? ...

Resolving views in Spring MVC with Freemarker - including jsp page

When using the FreemarkerServlet, it is possible to include JSP pages alongside Freemarker content. However, I'm using Freemarker as a view resolver in my Spring MVC application and so don't use the FreemarkerServlet. Is there any way I can still use @include_page in my Freemarker templates when I'm not using the FreemarkerServlet? Than...

Using timezone 'EST' in freemarker template

<#setting time_zone="America/New_York"> Time: ${response.currentDate?string("MM/dd/yyyy hh:mm a zzz")}. I need the timezone to be displayed as 'EST'. But currently, when i run the application and the email gets generated from the template above, it is displaying as 'EDT'. Can you please let me know what needs to be done to show as 'ES...

Setting freemarker template from classpath

I have a web application that I need to manually obtain a Freemarker template - the template is obtained via a class in a library project, but the actual tpl file is contained in the web application classpath. So, there are 2 projects, one 'taac-backend-api' and another 'taac-web'; taac-backend-api has the code to grab the template, and...

Freemarker: Reproduce XML

Folks, I am working on a freemarker template that needs to reproduce parts of the input XML tree. I would love to have a macro that I could invoke as follows: <@renderTree node=node namespace="ns"/> Anyone have something like this handy? Thanks. -Raj ...

FreeMarker Template JSON - Give it a node?nextSibling to find out, if the current node have a sibling?

I want to convert a XML File to JSON. The problem is, I have the structure Content ... Secon ... Secon ... Secon ... I want it to the JSON Format like: { "nodeid" : "34", "text" : "First level", "children" : [{ "nodeid" : "1", "text" : "Content ...", "leaf" : true ,"children" : [{ "nodeid" :...

First steps with freemarker with spring mvc

So I have Index action in my HomeController.java class. I have my freemarker templates in: /web-inf/ftl/test.ftl How can I load the template? I have this in my appname-servlet.xml: <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> <property name="suffix"> ...

can freemarker do second replacement

Usually i use this type of data in freemarker: (root) | +- website = "StackOverflow" | +- href = "http://stackoverflow.com" | +- label = "my favorite website." but today,a java programmer give me a model like this: (root) | +- website = "StackOverflow" | +- href = "http://stackoverflow.com${dir}" | +- label =...

Creating your own custom helpers with Freemarker?

From my controller I set my Model and view like: ModelAndView mav = new ModelAndView(); mav.setView("index"); mav.addObject("user", user); mav.addObject("someCollection", someCollection); return mav; Now I want to create a helper type object that will take the someCollection and the user object as parameters. My helper function wi...

Freemarker with spring mvc, so what will my action look like?

In my appname-servlet.xml I have: <!-- freemarker config --> <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <property name="templateLoaderPath" value="/WEB-INF/freemarker/"/> </bean> <!-- View resolvers can also be configured with ResourceBundles or XML files. If you need...

Iterating over map in Freemarker

I have a Hash Map which contain item ids as a key and Item objects as a value. Following is the pseudo code - allItems : { 12: itemObj1 (id:12, name:myitem1) 13: itemObj2 (id:13, name:myitem2) 14: itemObj3 (id:14, name:myitem3) } On result.ftl I need to iterate over this map and get the values of Item Object. I have tried this a...

how to use messages with freemarker in spring mvc?

In a .jsp I would use: <fmt:message key="welcome.title"/> to display a message from my messages.properties file. How would I do this with freemarker ? ...

header and footer and freemarker

My website has a consistant header and footer that I want on all pages. What is the best way to do this? The header will have some dynamic data also, based on the current view. P.S Does freemarker have any sort of master page functionality? Where I can create a base template, then have other templates build upon the base? Basically ...

Tutorial/sample app on SpringMVC, Tiles and FreeMarker integration

Hi, I'm trying to setup a new project using SpringMVC, Tiles and FreeMarker. So far I'm pretty lost between the TilesConfigurer, FreeMarkerConfigurer and the ViewResolvers. I have tried with several combinations of them but far no luck. I have also google a lot about it and I haven't really found a solid tutorial. Any suggestions? Car...

FreeMarker - Get Current URL

Is it possible to get the current page's URL in FTL? ...