Pathfinder
Pathfinder

Reputation: 994

Dynamic Page Title Thymeleaf Spring MVC

I'm using Thymeleaf for layouts in my project, but unable to get the page title dynamic.

Layout.jsp

<head th:fragment="headerfragment">
  <title th:text="@{page-title}"></title>
  <!-- Bootstrap Core CSS -->
  <link th:href="@{/resources/css/bootstrap.min.css}" rel="stylesheet"
    type="text/css" />
</head>

Page.jsp

<head th:include="layout :: headerfragment"></head>

When the final page is rendered i see title as page-title not the actual text

In my controller I set the page-title attribute

modelMap.addAttribute("page-title", "Home");

I might not be doing it right as i'm new to thymeleaf. Please help me to find out the solution.

Upvotes: 4

Views: 11312

Answers (1)

code
code

Reputation: 4231

The correct syntax is ${page-title} so in your example it should be changed to <title th:text="${page-title}"></title>

Upvotes: 12

Related Questions