I have some Rythm templates registry and need to develop code that will render selected by client template (e.g. client will call my code by http and provide template name and parameters).
Due to call is performed by http - on my end I will have client-provided params as JSON (I even have not classes that represent user input), maybe parsed to map of maps of maps...
. And It turn out that It's not handy to use such structure in template: all I can do is to use Map::get(key)
method and only with 1 level nesting:
Next template get error due to param.get("person")
is supposed as Object
and have not get(key)
method:
@args Map<String, Object> param
Hello @param.get("person").get("firstName").capFirst()!
I remember that some template engines support map-as-object syntax, e.g. pass map of maps of ... of objects
to template and access it in template as POJO (or like accessing JSON object's field in JS), for exapmle:
@args Map param
Hello @param.person.firstName.capFirst()!
Is it possible with Rythm?
Or maybe there is another convinient way to solve such problem?
Try dynamic evaluation by putting a @
at the end of the expression:
@args com.alibaba.fastjson.JSONObject param
Hello @param.person.firstName.capFirst()@!
See http://fiddle.rythmengine.org/#/editor/ed3855c628144af287571cdf9857bcaa