Probably the last thing, that let me say Thymeleaf has replaced JSP is the way of using freeform Thymeleaf fragments.
Tymeleaf provides th:include attribute, but is there a way of rendering output which doesn't have "html" as root attribute? Of course there is but not quite perfect.
I have fragment:
and I want to use it as a result of invokng AJAX method (to simply insert it somewhere using innerHTML, or jQuery's html()). But there's problem:
- if I use XHTML/HTML5/LEGACYHTML5 mode it requires DOCTYPE declaration
- if I use XML/VALIDXML mode, it results in:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div> < span>Mon Nov 07 09:09:47 CET 2011</ span> </div> [/code]
Unfortunately TemplateMode is enum and I can't extend it.
I'd like to user XML mode for fragments and XHTML mode for "root" templates (for entire pages) - the main problem is that OutputHandler's output() method uses:
and output() is invoked statically from org.thymeleaf.TemplateEngine.process()...
Summarizing, my requirements are:
- clean, beautiful template engine: checked
- natural templating: checked
- SpringMVC integration: checked
- DOCTYPE translation: checked
- fragments: almost - the problem is I want to be able to use both XHTML/HTML5 mode (for pages) and XML mode (for fragments used in AJAX responses).
Thanks for reply! I've seen this thread and read about $.load(), but I have a little mental blockade with:
... but then jQuery parses the returned document to find the element with an ID of container ...
I know it's really fast, but...
What in practice is convincing me is that writing full (with html and body elements) templates and loading only portions of them is still "natural templating" - you can open them in browser and see the final look.
However - one tiny more enum in TemplateMode (which doesn't require doctype and which won't produce XML declaration) should not harm anybody ;)