File tree Expand file tree Collapse file tree
main/java/com/hubspot/jinjava/objects/collections
test/java/com/hubspot/jinjava/objects/collections Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,6 +21,13 @@ protected Map<String, Object> delegate() {
2121 return map ;
2222 }
2323
24+ public Object get (String key , Object defaultValue ) {
25+ if (!map .containsKey (key )) {
26+ return defaultValue ;
27+ }
28+ return map .get (key );
29+ }
30+
2431 @ Override
2532 public Object put (String s , Object o ) {
2633 if (o == this ) {
Original file line number Diff line number Diff line change @@ -322,6 +322,18 @@ public void itGetsKeysWithVariableName() {
322322 .isEqualTo ("value1" );
323323 }
324324
325+ @ Test
326+ public void itSupportsGetWithOptionalDefault () {
327+ assertThat (
328+ jinjava .render (
329+ "{% set test = {\" key1\" : \" value1\" } %}" +
330+ "{{ test.get(\" key2\" , \" default\" ) }}" ,
331+ Collections .emptyMap ()
332+ )
333+ )
334+ .isEqualTo ("default" );
335+ }
336+
325337 @ Test
326338 public void itFallsBackUnknownVariableNameToString () {
327339 assertThat (
You can’t perform that action at this time.
0 commit comments