/** * Build a FreeMarker template model for the given model Map. * <p>The default implementation builds a {@link SimpleHash}. * @param model the model to use for rendering * @param exchange current exchange * @return the FreeMarker template model, as a {@link SimpleHash} or subclass thereof */ protected SimpleHash getTemplateModel(Map<String, Object> model, ServerWebExchange exchange) { SimpleHash fmModel = new SimpleHash(getObjectWrapper()); fmModel.putAll(model); return fmModel; }
map.putAll(attributeMap);
/** * Build a FreeMarker template model for the given model Map. * <p>The default implementation builds a {@link SimpleHash}. * @param model the model to use for rendering * @param exchange current exchange * @return the FreeMarker template model, as a {@link SimpleHash} or subclass thereof */ protected SimpleHash getTemplateModel(Map<String, Object> model, ServerWebExchange exchange) { SimpleHash fmModel = new SimpleHash(getObjectWrapper()); fmModel.putAll(model); return fmModel; }
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { if(!params.containsKey("with")) { throw new RuntimeException("\"with\" param was not provided"); } String withArgument = params.get("with").toString(); StringWriter innerContent = new StringWriter(); body.render(innerContent); SimpleHash envValues = getHash(env); envValues.putAll(params); envValues.put("page_content", innerContent.toString()); for(Object key : params.keySet()) { if(key.toString().equals("with")) { continue; } else { envValues.put(key.toString(), params.get(key)); } } String path = getTemplatePath(env.getTemplate().getName(), withArgument); Template template = env.getConfiguration().getTemplate(path + ".ftl"); template.process(envValues, env.getOut()); }