Basic Freemarker Configuration

Freemarker as Templating Technology have evolved a lot from it’s traditional peers like velocity and other scripting languages.

I just wanted to post few lines of code which i generally use in My FreemarkerUtility. Rename the download to .rar
FreeMarkerEngine

Few of Common Problem we Face with Freemarker are in using map
One of the Error is like

Expected hash. evaluated instead to freemarker.ext.beans.SimpleMethodModel

This has been overcomed by following piece of code


// Specify how templates will see the data-model. This is an advanced
// topic...
// but just use this:
cfg.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
BeansWrapper bw = (BeansWrapper)cfg.getObjectWrapper();
bw.setSimpleMapWrapper(true);
bw.setExposureLevel(BeansWrapper.EXPOSE_PROPERTIES_ONLY);
cfg.setObjectWrapper(bw);

Advertisements