public class ApiDirective implements TemplateDirectiveModel { private static final String VAR = "apis"; private static final String PARAM_VAR = "var"; @SuppressWarnings("rawtypes") public void execute( Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { List<Api> apis = Api.me.findAll(); String var = params.containsKey(PARAM_VAR) ? params.get(PARAM_VAR).toString() : VAR; env.setVariable(var, DEFAULT_WRAPPER.wrap(apis)); body.render(env.getOut()); }