I want to have a default "layout" page to load all of my scripts and dependencies into. From what I understand, velocity doesn't look for a default file to render through, so I kinda hacked my way around it. I save a default layout template as an instance variable. I then will put in the model the path to the template I would actually like to render.
public class App {
public static void main(String[] args) {
staticFileLocation("/public");
String layout = "templates/layout.vtl";
get("/", (request, response) -> {
HashMap<String, Object> model = new HashMap<String, Object>();
model.put("todos", request.session().attribute("todos"));
model.put("template", "templates/index.vtl");
return new ModelAndView(model, layout);
}, new VelocityTemplateEngine());
This feels very clunky to me, does anybody have any suggestions on how I could make this code a little bit easier to read?