Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a list inside Freemarker template

I have a set of functions_names that i generate while iterating a list of values. I want to capture these values "functions_names" in a list and use it for further processing. How can i do that?

Thanks

like image 368
S Kr Avatar asked Jun 05 '12 09:06

S Kr


People also ask

How do you add values on FreeMarker?

If you want to insert the value of an expression into a string, you can use ${...} (and the deprecated #{...} ) in string literals. ${...} in string literals behaves similarly as in text sections (so it goes through the same locale sensitive number and date/time formatting).

What is the use of FreeMarker template?

FreeMarker is a template engine, written in Java, and maintained by the Apache Foundation. We can use the FreeMarker Template Language, also known as FTL, to generate many text-based formats like web pages, email, or XML files.

How do you insert a line break in FreeMarker?

Learn more. Show activity on this post. In my code I am using "\n" for line breaks. It was suggested that I need to avoid "\n" because this is different for different OS (UNIX, windows and MAC) and each operating system would interpret this character differently.

Is FreeMarker template thread safe?

getTemplate(String) (and its overloads) does that (caching Template -s) for you, but the constructor of course doesn't, so it's up to you to solve then. Objects of this class meant to be handled as immutable and thus thread-safe.


1 Answers

FreeMarker doesn't support modifying collections. But if you really want to do this in FreeMarker (as opposed to in Java), you can use sequence concatenation: <#assign myList = myList + [newItem]>. Here you create a new sequence that wraps the two other sequences. Be aware that the resulting sequence is slow if you try to do indexed access in a long list constructed this way.

like image 87
ddekany Avatar answered Sep 28 '22 06:09

ddekany