Comment instead of remove

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Comment instead of remove

Sergey
Is something like this possible anyhow in current thymeleaf?

<div th:comment="${true}">...</div>

Which will transform into

<!- - <div>...</div> -->

Anyhow. I know that th:comment does not exist :)
Reply | Threaded
Open this post in threaded view
|

Re: Comment instead of remove

Emanuel
Administrator
I don't think you can do that using a combination of Thymeleaf's existing processors.  But you can definitely do that if you write your own dialect (extension) with an attribute processor that:
 - gets a string representation of the tag and its children
 - creates a new Comment node based on that string
 - inserts that comment node before the current tag
 - then removes the current non-commented tag
Reply | Threaded
Open this post in threaded view
|

Re: Comment instead of remove

Sergey
I think the most challenging task is to "get a string representation of the tag and its children"
If I try to do in Processor.processAttribute I get a not yet processed content.
Any ideas?
Reply | Threaded
Open this post in threaded view
|

Re: Comment instead of remove

Zemi
Administrator
When we have to process DOM elements after its execution, we use a trick consisting of creating a new element after the DOM fragment and invoke that later.

You could see an example following the code of this processor
   http://sourceforge.net/p/html5valdialect/code/67/tree/trunk/core/src/main/java/net/sourceforge/html5val/ValidateAttrProcessor.java

That delayed processor is invoked in line 26 of
  http://sourceforge.net/p/html5valdialect/code/67/tree/trunk/core/src/main/java/net/sourceforge/html5val/ValidateCommand.java