John P
John P

Reputation: 1221

Thymeleaf add css styles to html from variable

Let's say I have a variable cssStyles which contains some css as String. I want to send it in my html file in this way

<style>
    ${cssStyles}
</style>

How can this be achieved with thymeleaf?

Thanks!

Upvotes: 0

Views: 731

Answers (1)

Ralan
Ralan

Reputation: 804

At the very least you need to mark the style object that you'r using inline thymeleaf and use proper inline syntax. Below a mock of what I think might work.

See https://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#inlining for more information on how to do thymeleaf inlining

<style th:inline="text">
    [(${cssStyles})]
</style>

Upvotes: 1

Related Questions