java - Freemarker - template preprocessing -


i wondering, whether there way preprocess freemarker template rules - add syntactic sugar, not directive, nor method.

fo instance have variables, print this:

${item.getlocale(currentlocale).name} ${item.getlocale(currentlocale).text} ${item.parent.getlocale(currentlocale).name} ${item.parent.getlocale(currentlocale).text} 

obviously, getlocale construct makes whole expression pretty ugly. achieve able write:

${item.l.name} ${item.l.text} ${item.parent.l.name} ${item.parent.l.text} 

so .l. during compilation rewritten .getlocale(currentlocale).

is there nice way that? thanks!

this pretty why object wrapping exists in freemarker; can present data templates in custom way. suppose item belongs specific java class. extend defaultobjectwrapper or beanswrapper wrap items specially, , use configuration.setobjectwrapper(new yourobjectwrapper()) once initialize freemarker. (see source code of defaultobjectwrapper example of customization; extends beanswrapper wrap xml nodes, jython object, etc., specially.) when have ${item.name} in template, it's call yourhashmodel.get("name") on java side (where yourhashmodel extends freemarker.template.templatehashmodel), , in get method can have return new simplescalar(item.getlocale(currentlocale).get("name")) or like.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -