See everyone is interested in the template, I also say template, PHP

Source: Internet
Author: User
Tags php and


Template is actually the separation of PHP and HTML, some people also say MVC what.
PHP handler, save the dynamic content in the variable, and then output the contents of these variables through the template, this is the template
You can
$rows = $db->getall ($sql);
Require "tpl.html";
to output.
You can also
$tpl->setvar ("Rows", $rows);
$tpl->display ("tpl.html");
To output, in short he is the output variable inside the content.

I feel the template should have the following characteristics
1, is the HTML page
2, that is to see
3, simplified writing, easy to expand. (This is very important, in fact, is to change a simple form of writing)
Smarty custom functions are also available, and other templates have similar functionality. For example {article.addtime:date:y-m-d} {article.content:nl2br:}
If I can do the above three points, I feel is a good template.
A lot of people say to do HTML template directly with PHP, I compare against this form
The 1,php code is not visible.
2, it's too complicated to write.
If it looks trouble, writing is also trouble, I take the template to do, make a vase?

Discuz template is a good template, but 2, 32 point he did not very good, I also make a template. It's been used all the time, and what's worse is that he's a good template for me.
1, is the HTML page
2, see what it is, what you see, what the output is like. Unlike a lot of people to get a href= "$cssPath/css.css" so to get a, div+css page of this template to change the art of certainly not less hardship.
3, writing simplification is actually shorthand for the function. such as the above, such as the release time need to format can be arbitrarily changed, such as the content of the bar enter into line, such as to get the content of an editor. {content:htmleditor:}, for example .... , he is a shorthand, so that nothing can be done. Remember that page call? For example, the latest products show 8, the latest ... Displays 10. (many so-called CMS uses the label)
In fact, it's a foreach, the incoming argument returns a two-dimensional array.
And then there's the
<!--{Loop newproduct:sortid=1;limit=8 $product}-->
{product.productname:cut:20} ....
<!---{/loop}-->
One day the customer request changed, to call the essence of products, so
<!--{Loop newproduct:sortid=1;limit=8 $product}-->
into a
<!--{Loop newproduct:sortid=1;digest=1;limit=8 $product}-->
I feel this is simplification, art as long as understand, here should be the cycle on the line, to now and I have no one to cooperate with the art of the template, although he does not understand the program.
4, template bar, you want to pursue speed, Cachingit.
Is caching really useful? Why do I have to cache?
Many people say set the cache time, HTML caching is OK, this can be called caching? If it's a dynamic page, it's written
Welcome, {Username}, can you still cache him? You say do not cache it, the following calls too much, how to pinch?
This time to use the local cache, what is called local cache, is the cache page is also part of.
In fact, that is the call.
<!--{Loop newproduct:sortid=1;limit=8 $product}-->
The call to this place, if the home page shows 20 of the latest 5 articles, that open the pages, light these articles call will be 20 times query. Local Cache Bar
<!--{#loop newproduct:sortid=1;limit=8 $product}-->
Loop I add a # let him cache.
I add 20 #, the first page of the call is not DatabaseQuery, as if some places have to call the latest every time, how to do it, to remove it.

Template is a template, although only responsible for the display, not necessarily unimportant, if the template to make it simple is the problem we should consider.



</

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.