Thymeleaf and Conditional Comments

Thymeleaf doesn’t process anything placed inside of comments. That’s good. Most of the times. However, when you need to add some conditional comments for that good old Internet Explorer you’ll get into trouble. This won’t parse the URL for me:

<!--[if IE]><link rel="shortcut icon" data-th-href="${ portal.assetUrl({'_path=images/favicon.ico'}) }"/><![endif]-->

I’ve tried a lot of variations of that code. Even wrapping it in a tag and trying to inline-output the code. Doesn’t work.

<span data-th-inline="text" data-th-remove="tag">
	<!--[if IE]><link rel="shortcut icon" href="[[${ portal.assetUrl({'_path=images/favicon.ico'}) }]]"/><![endif]-->

An extension exists for this. Is this something you’re looking into adding in the future? Or is it possible to add myself when 6.0 comes?

Here’s the extension:

It’s still pretty common to have at least one or two conditional comments on your website for some old lingering IE bugs.

This seems to work as a workaround:

  <span data-th-utext="'&lt;!--[if IE]&gt;'" data-th-remove="tag"></span>
  <link rel="shortcut icon" data-th-...
  <span data-th-utext="'&lt;![endif]--&gt;'" data-th-remove="tag"></span>

Brilliant @toriverw, that works exactly as I needed =) Thank you!