Php template. The template is actually the separation of php and html, some people also say what mvc is. The php handler saves the dynamic content to the variables and then outputs the content of these variables through the template. this is the separation of the template from php and html. some people also say what mvc means.
The php handler saves the dynamic content to the variables and then outputs the content of these variables through the template. this is the template.
You can
$ Rows = $ db-> getAll ($ SQL );
Require "tpl.html ";
.
You can also
$ Tpl-> setVar ("rows", $ rows );
$ Tpl-> display ("tpl.html ");
In short, it is the content in the output variable.
I think the template should have the following features:
1 is the html page
2.
3. simplified writing and easy expansion. (This is very important. it is actually a simple form of writing)
Smarty user-defined functions and other templates have similar functions. For example, {article. addtime: date: Y-m-d} {article. content: nl2br :}
If we can achieve the above three points, I feel like a good template.
Many people say that php is used directly as an html template. I am opposed to this form.
1. php code is invisible.
2. writing is too complicated and too troublesome.
If it looks troublesome, writing is also troublesome. what can I do with a template and make a vase?
The discuz template is a good template. Unfortunately, he is not doing well at 2 or 3 points. I also made a template myself. I have been using it all the time. I can add anything for nothing, and it is a good template for me.
1 is the html page
2. you can see what you see and what the output looks like. Unlike a lot of people who want to launch an href = "$ cssPath/css.css", the templates such as p + css are certainly not hard to work.
3. simplified writing is actually short for functions. As shown in the preceding figure, for example, you can modify the content to be formatted during the release time. for example, you can press enter to change the content into a line break, for example, you can get the content to an editor. {Content: htmleditor:}, for example,..., is short for anything. Remember the call to that page? For example, eight latest products are displayed... 10. (Many so-called cms use tags)
To put it bluntly, it is a foreach. the input parameter returns a two-dimensional array.
So there is
{Product. productname: cut: 20 }....
One day, the customer's requirements changed. to call the best products
Changed
I think this is simplified. as long as the artist understands, this should be a loop. Up to now, there is no artist working with me who will not change my template, even though he doesn't understand the program.
4. Templates. you need to speed and cache them.
Is cache really useful? Why cache?
Many people say that setting the cache time is enough for html caching. can this be called caching? For dynamic web pages
Welcome, {username}. can you cache it? If you don't want to cache it, there are too many calls below. what should you do?
At this time, local cache is used. what is local cache is also part of the cache page.
In fact, that is, those calls.
If the home page displays the latest 5 articles of 20 categories, you can open the page to query 20 calls. Local cache
Loop I add a # to cache it.
I add 20 #, and there will be no database query for the homepage call. it seems that the latest call must be made every time. what should I do? remove.
A template is a template. although it is only for display, it is not necessarily important. if you make the template simple, we should consider it.
Bytes. The php handler saves the dynamic content to the variables and then outputs the content of these variables through the template. this is the template...