en Lopes
en Lopes

Reputation: 2113

Accessing properties file in Spring from Thymeleaf

I have a Thymeleaf template with this expression:

 <div class="box small">
                                <img th:src="'${@environment.getProperty('pics.path')} + '/' + ${user.id} + '/' + ${pic}"/>
                            </div>

but I have this error:

Could not parse as expression: "'${@environment.getProperty('pics.path')} + '/' + ${user.id} + '/' + ${pic}" (template: "joan" - line 528, col 38)

Upvotes: 0

Views: 731

Answers (1)

derkoe
derkoe

Reputation: 6281

There is a syntax error in your Thymeleaf expression - the first ' is not correct.

This should work:

<div class="box small">
  <img th:src="${@environment.getProperty('pics.path')} + '/' + ${user.id} + '/' + ${pic}"/>
</div>

When creating complex strings using literal substitutions is more readable - here is your example using this syntax:

<div class="box small">
  <img th:src="|${@environment.getProperty('pics.path')}/${user.id}/${pic}|"/>
</div>

Upvotes: 2

Related Questions