freemarker

Which Java HTML templating technology works in a way that is closest to Ruby (erb/haml)?

Among the Java templating solutions such as Apache Velocity, Freemarker, Hamlets, Tapestry, StringTemplate, JSP, JSP Weaver (others?) which would most closely approximate the conciseness and simplicity of similar HTML templating solutions in Ruby - haml/erb. I'm concerned both with the syntax of the templating engine as well as how simpl...

Ouput XML with Freemarker

We are using freemarker for templates in our web application. We are using spring's FreeMarkerViewResolver for this. Is there a way in freemarker to change the content type on the response to text/xml is there a way to do this in the template? ...

is freemarker safe when allow user edit their template

i'm new with freemarker, i need know about this problem too choose it or not, i will strip XSS by myself but i dont know are other features of freemarker safe when site allow user edit their template? ...

inserting XML elements in freemarker template using XPath

I'm using freemarker to do some XSLT-like transformations. I've created a working template, but it's ugly (see the example). But some of the elements aren't being transfomred at all. Is there a way I can use XPath expressions to insert entire elements into the XML? For example, <Root> <A> <B>bb</B> <c>cc</c> </A> <D> etc </D> <...

Can I use a JSP tag library with FreeMarker for a non-web context?

I was investigating FreeMarker (and also Velocity), and one of the things I liked about FreeMarker was that I could use it with my existing JSP tags. However, it's become my understanding that this will only work when using FreeMarker as a view for servlets. Is there a way to use these JSP tag libraries with either FreeMarker or Veloci...

change subvariable in FreeMarker

Is there a way to change a subvariable within a hash or a container in a FreeMarker template? For example, suppose I had: {"name":"Bob", "city":"Detroit", "state":"OH"} and I want to change the state to "MI". How would I go about doing that? I know about the assign tag, but the documentation says "Note that only top-level variables ca...

Implement a Custom Escaper in Freemarker

Freemarker has the ability to do text escaping using something like this: <#escape x as x?html> Foo: ${someVal} Bar: ${someOtherVal} </#escape> xml, xhtml, and html are all built in escapers. Is there a way to register a custom written escaper? I want to generate CSV and have each individual element escaped and that seems like a good ...

Using An Absolute Path With FreeMarker

I've been using FreeMarker for a little while now, but there's one glaring piece of functionality that is either missing or I just can't figure out (I hope the latter!). If you pass cfg.getTemplate() an absolute path, it just doesn't work. I know you can specify a template directory, but I can't afford to do that, my use case could dea...

How can I automatically validate that I have an HTML Id on every element?

The testers on my project want a unique HTML ID on every page element to make their automated testing easier. It's hard for me to remember to do this, because I don't need the IDs for development. How can I ensure that I don't forget? I thought maybe something like Checkstyle could tell me, or even the "inspections" in IntelliJ - but ...

How to get the request context in a freemaker template in spring

Hi, How to get the request context path in freemarker template when using with spring. My view resolver is like this <bean id="freeMarkerViewResolver" class="learn.common.web.view.FreemarkerViewResolver"> <property name="order" value="1" /> <property name="viewClass" value="org.springframework.web.servlet.view.fr...

Default escaping in Freemarker

In Freemarker templates we can use the escape directive to automatically apply an escaping to all interpolations inside the included block: <#escape x as x?html> <#-- name is escaped as html --> Hallo, ${name} </#escape> Is there a way to programmatically achieve a similar effect, defining a default escape applied to all interpola...

How do I call java methods on an object from a FreeMarker template?

Is it possible to call a method that takes parameters from a Freemarker template? I have an object model that I'm trying to render with Freemarker into a web page. One of the objects has a method to get a sublist of it's contents - taking a parameter that is used to filter the list: public List getunits(final String type); I know in J...

FreeMarker Current Date Comparison

Is it possible to do date comparisons against the current date in a freemarker template without passing the current date into the template? ...

Velocity vs. FreeMarker

Velocity or FreeMarker? They look pretty much the same, even the syntax? What to use? Or when to use what? ...

test if string can be converted to a number in FreeMarker

I am trying to test whether a string can be converted into a number in FreeMarker. For example, "123" and "3.14" can be converted, but "foo" can't. I know that I can test for this by using the number method on the string (e.g. "123"?number) and seeing whether it produces an error, but I am looking for a way to test for this without causi...

Turn off FreeMarker validation in Eclipse 3.5

I'm using Eclipse 3.5 with the FreeMarker template plugin, and it's showing me a syntax validation problem that I don't care to see. How do I turn this validation off, or possibly downgrade this template error to a warning? In previous versions of Eclipse, I'd probably look under Window -> Preferences -> Validation, but I don't see tha...

Freemarker iterating over hash map keys

Freemarker has two collection datatypes, lists and hashmaps Is there a way to iterate over hashmap keys just as we do with lists? so if i have a var with data lets say user : { name : "user" email : "[email protected]" homepage : "http://nosuchpage.org" } i would like t print all the user's properties with their value. This...

How to implement login mechanism in Alfresco Surf application

Hi all, i am playing around with alfresco WCM and want to implement a simple login mechanism in my surf application, so that I can show some information about the actual existing Alfresco user. Can anyone give me a hint? I already walked through http://www.benh.co.uk/alfresco/surf-part-1-getting-started/ but now I get stucked. Tha...

Expand a boolean variable to the string "true" or "false"

In a freemarker template I want to expand a boolean variable to a string like that: <#assign booleanVar = "test".isEmpty() /> state: ${booleanVar} <#-- this throws an exception! --> This is what I want to get as output: state: false The only way I found to reach this goal by now is: state: <#if booleanVar>true<#else>false</#if> ...

output date or datetime variable as a Unix timestamp in FreeMarker

Is it possible to output a date or datetime variable as a Unix timestamp in FreeMarker? I stumbled upon this page saying that it is possible to do it in Java by implementing TemplateMethodModelEx, but I am looking for an easier way. Does anyone know of a way to do it completely within FreeMarker(FTL)? ...