Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 378
Pathfinder Avatar asked Feb 08 '23 00:02

Pathfinder


1 Answers

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

like image 60
code Avatar answered Feb 24 '23 02:02

code