perwendel / spark-template-engines

Repository for different Template engine implementations.
Apache License 2.0
134 stars 101 forks source link

[Thymeleaf] Support for "Link URLs" #43

Open mthmulders opened 8 years ago

mthmulders commented 8 years ago

Thymeleaf has some nice features when it comes to rendering (hyper)links. It would be cool if we could use these from Spark applications as well.

But to use these features, one needs to supply anIWebContext instance to the Thymeleaf TemplateEngine. Building one requires access to the HttpServletRequest, HttpServletResponse, ServletContext, and optionally Locale. As far as I can see, none of these are available inside TemplateEngine#render. Am I missing the point how to get hold of them?

mthmulders commented 8 years ago

This might be less difficiult after upgrading to Thymeleaf 3, since the Thymeleaf 3 ten-minute migration guide states that Thymeleaf 3 is capable of running

truly independent from the Servlet API in web environments that do not make use of Java Servlets

Although Spark does use the Servlet API under the hood, it might be easier to use the aforementioned features with Thymeleaf 3 than it currently is with Thymeleaf 2.

mthmulders commented 8 years ago

I have a working prototype for this, but it requires https://github.com/perwendel/spark/pull/658 to be merged.

atomfrede commented 7 years ago

@perwendel It would be awesome to use the IWebContext with thymeleaf3

mthmulders commented 4 years ago

I have a working prototype for this, but it requires perwendel/spark#658 to be merged.

Note to future self... The prototype involves extending Thymeleaf's StandardLinkBuilder, overriding the computeContextPath() method to use ServletFlag.getContextPath() (introduced with perwendel/spark#658).