The fragment of Thymeleaf

Source: Internet
Author: User

Mueas project, the Web front end uses thymeleaf as the presentation layer. This view parser, personally feel very good. Simple and performance is better! Personal feel than JSP and freemarker, such as simple and easy to use!

Today simply record the use of fragment, this class is the JSP tag, but it is very simple. In the HTML file, you can wrap up the block of elements that you think might appear in multiple places with fragment!

For example:

1 <!DOCTYPE HTML>2 <HTML>3   <Head>4     ...5   </Head>6   <Body>7      <Div  th:fragment= "Footer"> 8       &copy;Footer9     </Div>Ten   </Body> One </HTML>

In the place of use, and then use the include tag to introduce it!

For example:

1 <!DOCTYPE HTML>2 <HTML>3   <Head>4     <!--/* Each token would be replaced to their respective titles in the resulting page. * / -5     <titleLayout:title-pattern= "$DECORATOR _title-$CONTENT _title">Task List</title>6     ...7   </Head>8   <Body>9     <!--/ * Standard layout can is mixed with layout dialect * / -Ten     <DivTh:replace= "Fragments/header:: Header"> One       ... A     </Div> -     <Divclass= "Container"> -       <Divlayout:fragment= "Content"> the         <!-- ============================================================================  - -         <!--This content was only used for static prototyping purposes (natural templates) - -         <!--and is therefore entirely optional, as this markup fragment would be included - -         <!--From ' fragments/header.html ' at runtime.  - +         <!-- ============================================================================  - -         <H1>Static content for prototyping purposes only</H1> +         <P> A Lorem ipsum dolor sit amet, consectetur adipiscing elit. at praesent scelerisque neque neque, ac elementum quam dignissim interdum. - phasellus et placerat elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. - praesent scelerisque neque neque, ac elementum quam dignissim interdum. - phasellus et placerat elit. -         </P> -       </Div> in       <DivTh:replace= "Fragments/footer:: Footer">&copy;The Static Templates</Div> -     </Div> to   </Body> + </HTML>

Note: Th:fragment defined fragments, where needed, can be brought in with Th:include or Th:replace!

Also, all fragment can be written in a file or can exist separately. Can be part of an HTML file. As long as you need to, bring the Th:fragment label to define it, and make it a fragment. It is important to note that the path of the file where the fragment is located, to separate the path with "/", the root path is the path where templates is located.

Like what:

1 <Body>2     <Divclass= "Container">3         <DivTh:include= "exam/special/geeker/geeker:: Geeker-base-header"></Div>4         <Divclass= "Geeker-content">5             <DivTh:include= "Exam/special/geeker/geeker::geeker-base-left"></Div>            6             <Divclass= "Geeker-main">7             </Div>8             <Divclass= "Geeker-right">9             </Div>Ten         </Div> One     </Div> A </Body>

Isn't it very easy to use? I feel very good!

The fragment of Thymeleaf

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.