Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Freemarker - access value at a particular key in map

I have Map variable in my Freemarker template. How can I fetch a value at a particular key in the map, as we do in Java (map.get(<key>)).

I know how to iterate through keys and values of a map in a FTL. But I want a solution without iteration, on the lines of Java get() method of Map interface.

like image 831
sam100rav Avatar asked Aug 31 '16 11:08

sam100rav


People also ask

How do I get the value of a map for a specific key?

util. HashMap. get() method of HashMap class is used to retrieve or fetch the value mapped by a particular key mentioned in the parameter. It returns NULL when the map contains no such mapping for the key.

How do you generate random numbers in FreeMarker?

Freemarker does not provide a random number generator at the moment. You can implement a naive random number generator using the time ( . now ) as a seed, but it should never be a critical part of your program. Save this answer.

How do you comment on FreeMarker?

Comments: Comments are similar to HTML comments, but they are delimited by <#-- and --> . Comments will be ignored by FreeMarker, and will not be written to the output.


1 Answers

map[dynamicKey] or map.staticKey if the key is a string. Due to historical limitations, if the key isn't a string, map?api.get(nonStringKey).

like image 165
ddekany Avatar answered Oct 23 '22 09:10

ddekany