Search code examples
thymeleaf

Thymeleaf: Setting attributes with namespace


In a Spring Boot application I try to set an attribute with namespace. Here's what I tried:

<svg id="svg1" width="100%" viewBox="0 0 400 100" xmlns="http://www.w3.org/2000/svg"
     xmlns:th="http://www.thymeleaf.org"
     xmlns:xlink="http://www.w3.org/1999/xlink">
...
     <image th:attr="x=${thumbx},xlink:href=${thumbfile}" 
      x="150" y="50" width="20" height="20"  
      xlink:href="http://s3.amazonaws.com/some.png"/>
...
</svg>

That raises org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as assignation sequence: "x=${thumbx},xlink:href=${thumbfile}".

Any ideas on how to set the attribute xlink:href?


Solution

  • Try to wrap the attribute name with simple quotes:

    <image th:attr="x=${thumbx},'xlink:href'=${thumbfile}" />