Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thymeleaf: Setting an arbitrary value to an arbitrary attribute

In my Thymeleaf template I need to set a custom attribute to a dynamically generated value. How would I do that?

I tried th:attr="name=value", but it seems to be pretty much strict about the 'value' part. For instance, I tried to generate the following attribute:

<div ng-init="myUrl='http://myhost.com/something'> ... </div>

where http://myhost.com/something is a dynamic part of the ng-init attrubute and is generated by Thymeleaf's URL expression, like @{...}

Any suggestions how to compose an expression that would produce the above piece of HTML?

like image 582
Alex Vayda Avatar asked Jul 12 '13 17:07

Alex Vayda


1 Answers

Give this a try:

<div th:attr="ng-init='myUrl=\'' + @{http://myhost.com/something} + '\''">...</div>

It will output:

<div ng-init="myUrl=&#39;http://myhost.com/something&#39;">...</div>
like image 121
Damien Avatar answered Sep 27 '22 15:09

Damien