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.