What is the easiest way to use a straight HTML page as a Spark template (IE, I don't want to go through a TemplateEngine
implementation).
I can use a template engine fine, like so:
Spark.get("/test", (req, res) -> new ModelAndView(map, "template.html"), new MustacheTemplateEngine());
And I tried just using the ModelAndView without an Engine:
Spark.get("/", (req, res) -> new ModelAndView(new HashMap(), "index.html"));
But that get's me just the toString() of the model and view: spark.ModelAndView@3bdadfd8
.
I am thinking of writing my own engine and implementing render() to do the IO to serve the html file, but is there a better way?
Updated Answer
With the help of the answer provided here, I have updated this answer.
Old Answer
Unfortunately, I have found no other solution than to override the
render()
method in your ownTemplateEngine
. Please note the following uses Java NIO for reading in the contents of a file:Then, in your route you call the
HTMLTemplateEngine
as follows:Another One Line solution that can help:
You need this import: import spark.utils.IOUtils;
source : https://github.com/perwendel/spark/issues/550
You don't want a template engine. All you want is to get the content of the HTML files.