In Java:
Map<String, Object> model = new HashMap<>();
Map<String, String> items = new HashMap<>();
items.put("color", "red");
model.put("items", items);
I now want to include a snippet in my rendered template if items
contains the key color
.
<#if ???? >
the map contains a key called color
</#if>
What do I replace the ???? with?
util. HashMap. containsKey() method is used to check whether a particular key is being mapped into the HashMap or not. It takes the key element as a parameter and returns True if that element is mapped in the map.
FTL just generates text on the server, like HTML, CSS, whatever, then the client (browser) just gets the output. So, assuming you generate HTML with FTL, you put images into it with <img src="..."> . To learn about FreeMarker, go to http://freemarker.org/docs/index.html, of course. Save this answer.
You can use ??
operator like this:
<#if items['color']?? >
the map contains a key called color
</#if>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With