Thymeleaf Layout Dialect 적용하기

2022. 7. 28. 17:34·개발/thymeleaf
728x90

레이아웃용 파일을 만들어 놓고 각 페이지에서 원하는 레이아웃 파일을 상속받아서 필요한 부분만 교체해서 사용한다.

 

- 환경

IDE : STS

JDK : 1.8

Spring Boot : 2.7

Gradle

 

 

1. gradle Layout dialect 추가

dependencies {
	implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:3.0.0'
}

 

2. 파일 경로 확인

3. layout 파일 추가

<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">

<!-- 헤드  -->
<div th:replace="fragment/head :: head"></div>

<body id="page-top">

    <!-- Page Wrapper -->
    <div id="wrapper">
		<!-- 사이드 바  -->
        <div th:replace="fragment/sidebar :: sidebar"></div>
        <!-- Content Wrapper -->
        <div id="content-wrapper" class="d-flex flex-column">

            <!-- Main Content -->
            <div id="content">
                <div th:replace="fragment/topbar :: topbar"></div>
                <!-- Begin Page Content -->
                <!-- <div th:replace="fragment/pageContent :: pagecontent"></div> -->
                <!-- 본문  -->
                <th:block layout:fragment="content"></th:block>
            </div>
            <!-- End of Main Content -->

            <!-- Footer -->
            <div th:replace="fragment/footer :: footer"></div>
            <!-- End of Footer -->
        </div>
        <!-- End of Content Wrapper -->
    </div>
    <!-- End of Page Wrapper -->

    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
        <i class="fas fa-angle-up"></i>
    </a>

    <div th:replace="fragment/script :: script"></div>

</body>

</html>
  • 이전 글의 index.html 파일이 layout.html 수정 되었습니다.
  • [xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" ] 추가
  • <th:block layout:fragment="content"></th:block> 추가  이 부분만 내용이 변경될 부분이다.  

4. index.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="fragment/layout">

<th:block layout:fragment="content">
    <!-- Begin Page Content -->
    <div class="container-fluid">
        <h1>레이아웃 수정하는 페이지</h1>
    </div>
</th:block>

</html>
  • xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"  추가
  • layout:decorate="fragment/layout"  추가
  • <th:block layout:fragment="content"> </th:block>  추가

5. 완료 화면 

inex.html 페이지

 

- 참고

URL : https://dev-jwblog.tistory.com/34

728x90

'개발 > thymeleaf' 카테고리의 다른 글

[HTML] script 위치  (0) 2022.08.02
spring boot thymeleaf 에 Datatables 적용하기  (0) 2022.08.01
thymeleaf (bootstrap sb-admin)공통영역 처리  (0) 2022.07.28
[springboot thymeleaf] bootstrap sb-admin2 적용  (0) 2022.07.27
'개발/thymeleaf' 카테고리의 다른 글
  • [HTML] script 위치
  • spring boot thymeleaf 에 Datatables 적용하기
  • thymeleaf (bootstrap sb-admin)공통영역 처리
  • [springboot thymeleaf] bootstrap sb-admin2 적용
nix-be
nix-be
  • nix-be
    NiX
    nix-be
  • 전체
    오늘
    어제
    • 홈
      • 책
        • 오브젝트
      • 성장
        • jpa Querydsl 정리
        • 코딩테스트
      • 인프라
        • linux
        • vmware
        • CI&CD
        • 네트워크
        • docker
      • 개발
        • spring boot
        • JPA
        • java
        • thymeleaf
        • 이슈
        • jquery
        • javascript
        • 안드로이드
      • DB
        • postgreSql
      • 잡다한것
        • 프로그램
        • 일상 관련
      • 회사
        • 티
  • 블로그 메뉴

    • 홈
    • 개발
  • 링크

  • 공지사항

  • 인기 글

  • 태그

  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
nix-be
Thymeleaf Layout Dialect 적용하기
상단으로

티스토리툴바