Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append a thymeleaf variable in an <img > tag that has a src?

Cant seem to find the correct syntax for this?

<img id='barcode' src="https://api.qrserver.com/v1/create-qr-code/?data="'+ ${var.membervar} + "'+&amp;size=100x100" alt="" title="HELLO" width="50" height="50" />
like image 628
Jessica Jones Avatar asked Dec 02 '25 11:12

Jessica Jones


1 Answers

You should let Thymeleaf know you want to parse the src attribute by using th:src. Something like this would work ...

<img id='barcode' th:src="'https://api.qrserver.com/v1/create-qr-code/?data='+ ${var.membervar} + '&amp;size=100x100'" alt="" title="HELLO" width="50" height="50" />

But for the fully qualified URLs you should be using Thymeleaf Link Urls where proper encoding will be applied for all your query parameters. For example ...

<img id='barcode' th:src="@{https://api.qrserver.com/v1/create-qr-code/(data=${var.membervar},size='100x100')}" alt="" title="HELLO" width="50" height="50" />
like image 125
Slava Ivanov Avatar answered Dec 04 '25 01:12

Slava Ivanov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!