Dynamically generated link to posts in Thymeleaf?

So I have the following code:

 <h3 th:if="#{${'footer.message.' + receiptProperties.url}? : '(NOTHING)'}"  th:utext="#{${'footer.message.' + receiptProperties.url}}"></h3>

      

receiptProperties.url = the name assigned to the tenant, such as ABC, DEF, etc. Thus, the key in the messages.properties file will look like footer.message.ABC = Hello ABC!

The dynamically generated message key is displayed correctly, however, if there is no key such as footer.message.GHI in the properties file , then instead of displaying nothing, on the page: ?? footer.message.GHI_en ??

Is there a way in Thymeleaf to check exactly if a dynamically generated key exists in the properties file?

+3


source to share


1 answer


the message utility has methods that you can use to do this. You can use an expression like:



${#messages.msgOrNull('footer.message.' + receiptProperties.url) == null ? 'Invalid key' : 'Valid key'}

      

+2


source







All Articles