Thymeleaf add value in style
Most probably you are having a syntax issue here. Try the following code:
th:styleappend="'background-position:-' + @{${value}} + '%'"
Set CSS variables from model object in Thymeleaf
If you want to set CSS variables, you should use CSS inlining.
<style th:inline="css">
:root {
--primary-color: [[${brandingConfig?.themeConfig?.primaryColor} ?: '#633EA5']];
--secondary-color: [[${brandingConfig?.themeConfig?.secondaryColor} ?: '#E9E6ED']];
}
</style>
Normally the Thymeleaf processor only evaluates expressions in th:*
attributes of tags. However, if you set th:inline="css"
on your style tag you can use [[...]]
expressions to evaluate the text inside a tag.
Thymeleaf into style /style
You have to explicitly tell Thymeleaf to look for expressions in text with th:inline
attribute, and than surround the expression with double square brackets.
<style th:inline="text">
paper-scroll-header-panel{
--paper-scroll-header-panel-full-header: {
background-image: url([[@{(${session.user.coverImagePath})}]]);
};
}
</style>
The authors of Thymeleaf have chosen this scheme for performance reasons, because the Thymeleaf's template parsing and processing is very different compared to JSP or Facelets.
How to do if-else in Thymeleaf?
Thymeleaf has an equivalent to <c:choose>
and <c:when>
: the th:switch
and th:case
attributes introduced in Thymeleaf 2.0.
They work as you'd expect, using *
for the default case:
<div th:switch="${user.role}">
<p th:case="'admin'">User is an administrator</p>
<p th:case="#{roles.manager}">User is a manager</p>
<p th:case="*">User is some other thing</p>
</div>
See this for a quick explanation of syntax (or the Thymeleaf tutorials).
Disclaimer: As required by StackOverflow rules, I'm the author of Thymeleaf.
Thymeleaf th:text - Put a text without removing HTML structures
I faced the same problem. The answer is th:inline='text'
This should solve your issue
<h1 th:inline="text" >
[[${header.title}]]
<small th:text="${header.subtitle}">Subtitle</small>
</h1>
or you can also use th:remove="tag"
<h1>
<span th:text="${header.title}" th:remove="tag">title</span>
<small th:text="${header.subtitle}" >Subtitle</small>
</h1>
Related Topics
CSS Difference Between Background: and Background-Image:
How to Center Variable Width Divs in CSS
How to Get Cross Browser Compatibility in Print on Page from All Browsers
Why Do Anchor Pseudo-Classes A:Link, :Visited, :Hover, :Active Need to Be in Correct Order
CSS Sibling Absolute Positioning
Div with Scrollbar Inside Div with Position:Fixed
Bootstrap 4 Invalid Feedback with Input Group Not Displaying
Make Overlay Background Click-Through-Able
CSS Rotation with Respect to a Reference Point
Negative Top Margin Not Working in Ie 8 or 9
Visual Studio Intellisense for Bootstrap via Cdn
How to Define a Less Mixin to Generate a Transition-Property with a Variable Number of Parameters
CSS - Circle with Margin on Border
CSS Display Inline-Block Issue with Ie
How to Detect Element Visibility Using Only CSS
Clicking a Child Doesn't Trigger the Parent's :Active State in Ie