Skip to content

Commit

Permalink
Fix creation template model using Map.of (for java 9+)
Browse files Browse the repository at this point in the history
  • Loading branch information
decebals committed Dec 12, 2021
1 parent 1f21a6d commit f0b1ccf
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pippo-core/src/main/java/ro/pippo/core/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -1043,18 +1043,21 @@ public String renderToString(String templateName, Map<String, Object> model) {
throw new PippoRuntimeException("You must set a template engine in your application");
}

// extended model (add extra fields)
Map<String, Object> extendedModel = new HashMap<>(model);

// merge the model passed with the locals data
model.putAll(getLocals());
extendedModel.putAll(getLocals());

// add session (if exists) to model
Session session = Session.get();
if (session != null) {
model.put("session", session);
extendedModel.put("session", session);
}

// render the template using the merged model
StringWriter stringWriter = new StringWriter();
templateEngine.renderResource(templateName, model, stringWriter);
templateEngine.renderResource(templateName, extendedModel, stringWriter);

return stringWriter.toString();
}
Expand Down

0 comments on commit f0b1ccf

Please sign in to comment.