While using Spring Boot
with Thymeleaf
in Intellij Idea it is possible that the syntax for the template engine is not recogniced by the IDE. In this example it the tag th:href
.
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="http://cdn.jsdelivr.net/webjars/bootstrap/3.3.2/css/bootstrap.min.css"
th:href="@{/webjars/bootstrap/3.3.2/css/bootstrap.min.css}"
rel="stylesheet" media="screen"/>
<link href="/css/justified-nav.css" />
</head>
<body>
</body>
</html>
The problem is a missing namespace declaration xmlns:th=”http://www.thymeleaf.org”
in the html
root element. The full solution would look like this:
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Hello</title>
</head>
<body>
</body>
</html>
If you are using Spring
you should use the following:
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Hello</title>
</head>
<body>
</body>
</html>
The difference is in the DOCTYPE
.