I'm setting up a new website and I'd like to have multiple files for re-usable components (header, footer, common imports on , scripts, etc). I also want to have files for each layout (combining the components I defined), like "Main Application", "Full Screen Dashboard" etc. Finnaly, I want to create pages with just the content I need and then plug that into the layout of my choice.
Something like this: Diagram of files
I have looked at this question but that requires me to call on java the layout with my content as a parameter instead of defining on my content what layout to use.
I've also considered just using my "layouts" as templates, then copy+paste into a new "content" file and edit the placeholders out.
This is a sample controller:
@View("ticketing/home") @Get("/") public HttpResponse home() { final Map<String, Object> resultMap = new HashMap<>(); resultMap.put("requests", ticketingClient.getSummaryRequests()); //Returns a list of tickets to be displayed. return HttpResponse.ok(resultMap); //Maps the resultMap variable to the ticketing/home thymeleaf template } This is how I'd like to have my content file structured:
<html> <head> <title>Tickets</title> </head> <body> <div> <p>My Content is here!</p> <img src="wow.jpeg"> </div> </body> </html> this is what I have now for my layout:
<html xmlns:th="http://www.thymeleaf.org"> <head> <title>Application Layout</title> <th:block th:include="./fragments/head.html :: imports"></th:block> </head> <body> <div id="wrapper"> <!-- Sidebar Menu --> <div th:replace="./fragments/sidebar.html :: sidebar"></div> <div id="page-wrapper" class="gray-bg"> <!-- Navigation Menu --> <div th:replace="./fragments/topbar.html :: topbar"></div> <!-- Page Header --> <div th:replace="./fragments/pageheader.html :: pageheader"></div> <!-- Main Content --> <div class="wrapper wrapper-content animated fadeInUp" th:fragment="content"> <div class="row"> <div class="col-lg-12"> <div class="wrapper wrapper-content"> <p>Content here</p> </div> </div> </div> </div> </div> </div> <div th:replace="./fragments/footer.html :: footer"></div> <th:block th:replace="./fragments/scripts.html :: scripts"></th:block> </body> </html> I expect to be able to use the same java syntax (with the annotations) to use my views.
I'd rather change more in the content file than on the layout file.