Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using variable inside src image with Thymleaf template

I developped an application using spring-boot and thymeleaf as a template in my view I try to use a variable inside a loop but it's not worked. This is a snippet of my code:

<table >
    <thead>
        <tr>
            <th>Type</th>
            <th>Résumé</th>
            <th>Contenu</th>
        </tr>
    </thead>
    <tbody>
        <tr th:each="subTask  : ${lstOtherSubTasks}">
            <td><img th:src="@{/img/icons/${subTask.issueTypeId}.png}" title="TODO" />     // here the variable ${subTask.issueTypeId} not works
            <p th:text="${subTask.issueTypeId}" />   here the value of the variable ${subTask.issueTypeId} is not null I get the good value 
            </td>
            <td th:text="${subTask.resume}"></td>
            <td th:text="${subTask.contenu}"></td>
        </tr>
    </tbody>
</table>
like image 370
Amine Hatim Avatar asked Nov 28 '22 06:11

Amine Hatim


1 Answers

You can't mix expressions and strings like you're doing. This works:

 <img th:src="@{${'/img/icons/' + subTask.issueTypeId + '.png'}}" title="TODO" />
like image 98
Metroids Avatar answered Dec 04 '22 06:12

Metroids