swch
swch

Reputation: 1546

Working with thymeleaf fragments

I'm working on app with Spring and Thymeleaf and I wonder how to work with thymeleaf fragments.

The advantage of Thymeleaf vs JSP is that we don't have to run application to see the template, but, when we split the template to fragments it will look like this:

<body>
    <nav th:replace="fragments/header :: navbarMain"></nav>
    <div th:replace="fragments/header :: modalLogin"></div>
</body>

The problem is that without running the app, the template will not be processed and we will see nothing in browser. What is the good practice to deal with such scenarios? Should I create "fake" navbar here and then use th:replace, like:

<body>
    <nav th:replace="fragments/header :: navbarMain" class="fake-header"></nav>
    <div th:replace="fragments/header :: modalLogin"></div>
</body>

or there is some better way?

Upvotes: 1

Views: 429

Answers (1)

Antoniossss
Antoniossss

Reputation: 32517

Yes, you should only include fake placeholders for your prototyping. There is nothing wrong with that.

You can also use some custom solutions like this

https://github.com/BlackPepperSoftware/thymeleaf-fragment.js

Upvotes: 2

Related Questions