message property inside img src attr

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

message property inside img src attr

apprentice
Hi,

Whats the correct way to display a message property inside an src attr. I tried the following which is incorrect.

app.properties file

avatar.dir=/foo/bar

in html file I have

< img th:attr="=#{avatar.dir}+'/'+${id}" >

which outputs

<img src="??avatar.dir_en_US??/1/"...

It should be: /foo/bar/1

Thanks


Reply | Threaded
Open this post in threaded view
|

Re: message property inside img src attr

Zemi
Administrator
Hello,

if the text ??avatar.dir_en_US?? is shown, it's because the message resolution did not happen properly, so you'll have to check your i18n configuration, check http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#using-thtext-and-externalizing-text

By the way, you can use th:src instead of th:attr.

Regards,
  Zemi

Reply | Threaded
Open this post in threaded view
|

Re: message property inside img src attr

apprentice
Then all messages should fail but others such as the following display properly. <label th:text="#{label.avatar}">.

Reply | Threaded
Open this post in threaded view
|

Re: message property inside img src attr

Zemi
Administrator
Yes, both messages should display, as long as they are in the same messages file.

As far as Thymeleaf is concerned, there is no difference between an image tag and a label tag.

Regards,
   Zemi

Reply | Threaded
Open this post in threaded view
|

Re: message property inside img src attr

apprentice
The messages were in two distinct files. Thanks