Problem: <head> tag content is rendered inside <body>...

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem: <head> tag content is rendered inside <body>...

Maciej
This post was updated on .
Hi, I'm facing following issue since I started to use Thymeleaf Layout Dialect:

I've got layout.html:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
  
<head>
    <link rel="stylesheet" type="text/css" href="/resources/bootstrap/css/bootstrap.css" th:href="@{/resources/bootstrap/css/bootstrap.css}"/>
    <link rel="stylesheet" type="text/css" href="/resources/bootstrap/css/signin.css" th:href="@{/resources/bootstrap/css/signin.css}"/>
    <link rel="stylesheet" type="text/css" href="/resources/bootstrap/css/sticky-footer.css" th:href="@{/resources/bootstrap/css/sticky-footer.css}"/>


    <title layout:title-pattern="$DECORATOR_TITLE - $CONTENT_TITLE">Appone</title>
</head>
  
<body>

    <div th:replace="fragments/navbar :: navbar">
        <p class="center-block">DEFAULT HEADER</p>
    </div>

    <div class="container">

        <div layout:fragment="content">
            <p class="center-block">

DEFAULT CONTENT

</p>
        </div>

    </div>

    <div th:replace="fragments/footer :: footer">
        <p class="center-block">DEFAULT FOOTER</p>
    </div>

</body>
</html>

and login.html:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorator="layout">
  
<head>
    <title>Login page</title>
</head>
  
<body>

    <div layout:fragment="content">


    </div>

</body>
</html>


and the resulting html output when I hit //login in a browser is as follows:

<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>  

    <title>Appone - Login page</title>
    <link href="/appone/resources/bootstrap/css/bootstrap.css" type="text/css" rel="stylesheet">
    <link href="/appone/resources/bootstrap/css/signin.css" type="text/css" rel="stylesheet">
    <link href="/appone/resources/bootstrap/css/sticky-footer.css" type="text/css" rel="stylesheet">


</body></html>

Do anyone knows why the <head> is empty and its content went straight to the body? How to fix that?

EDIT: I just checked the BOM - there is none in any of my files. Request that comes to the browser seems OK - the <head> i fulfilled with metadata, but the browser (FF and Chrome) are displaying empty <head>. Anyone?
Reply | Threaded
Open this post in threaded view
|

Re: Problem: <head> tag content is rendered inside <body>...

Zemi
Administrator
Hello,

layout:decorator attribute value should be "layout.html" instead of "layout.html". Could be related?

Regards,
   Zemi


Reply | Threaded
Open this post in threaded view
|

Re: Problem: <head> tag content is rendered inside <body>...

Maciej
Hi Zemi, thats not the issue - when I add "layout.html" there is view resolver exception, so that part seems correct to me. Do you have any other hints?
Reply | Threaded
Open this post in threaded view
|

Re: Problem: <head> tag content is rendered inside <body>...

Emanuel
Administrator
In reply to this post by Maciej
I can't really see anything wrong with your templates.  In fact, it almost looks exactly like the examples I use for the layout dialect, which in turn are loosely based off the templates I use in my own projects so are working in live/production environments :/

Do you think you could get this into a Thymeleaf test file format so you can raise it as a possible bug against the layout dialect GitHub?
Reply | Threaded
Open this post in threaded view
|

Re: Problem: <head> tag content is rendered inside <body>...

Rocky
In reply to this post by Maciej
Hello,

Did you resolve this problem? If so can you please tell me how you have resolved it ? I am facing the same issue. The head content is appearing in body  tags after I started using thymeleaf layout decorators. Please help. Thanks !
Reply | Threaded
Open this post in threaded view
|

Re: Problem: <head> tag content is rendered inside <body>...

Miha_x64
In reply to this post by Maciej
You need to addDialect(new LayoutDialect()) to your Thymeleaf config. It is in this artifact.