How to make common modules of the template in tp framework development

Source: Internet
Author: User
For example, how do I share the top menu and the unchanged bottom part of a website using a template or do I inherit from the template? Thank you for answering. For example, how do I share the unchanged top menu and bottom part of a website using a template? inheritance? method? Thank you for answering.

Reply content:

For example, how do I share the top menu and the unchanged bottom part of the website using a template or something? Thank you!

I generally use a template for inheritance. For example, I write the header and tail file in base.html.

.......
        
   

.....

Copyright by XXXXXX

Then you can directly inherit the base.htmlfile on your website page, such as test.html.


  
  
   ....
  
  
   .....
  

In this way, you can change the part you want to change and try to reuse the code.

You can also see where my files are stored.

Thank you for your invitation. Actually, I don't know how to write it.php.

However, adhering to the principle of "combination is better than inheritance", I personally think that iftpContainsincludeIf other keywords are available, it is more flexible to write templates by combining them.

Of course, because I don'ttpTherefore, the analysis may not be accurate and is for reference only.

The built-in template engine has the include tag.

The correct method is to useLayoutInstead of using include only, each layout is for all pages.Maximum number of public approx.That is, the content in the layout file is the content of all pages: Header, navigation, tail, and even bread. Other pages can inherit the layout.

If there are multiple la s, for example, some page headers are different, you can use another layout, or split the headers and use include

Pseudocode:

All pages inherit the layout:

  

Include: public/top [top] include: public/header [header] include: public/menu [menu]

Include 'public/copyright' [About Us] include 'public/copyright' [copyright information]

The simplest example is to create headerand footerunder the publicof viewand layout.html under view. in layout, include header and footer, and use {_ CONTENT _} to change CONTENT in the middle. Enable layout_on => true and layout_name => 'layout ', for detailed usage, see layout usage in the template layout of the manual.

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.