Template framework for making static websites with PHP (ii) _php tutorial

Source: Internet
Author: User
The PHP code is all saved to a separate file, which is the file that is actually called by the page URL. The Web server parses the file through the PHP engine and returns the results to the browser. In general, PHP code always dynamically generates page content, such as querying a database or performing some sort of calculation. Here is an example:



example.php
Require (' class. Fasttemplate.php ');
$TPL = new Fasttemplate ('. ');
$TPL->define (' main ' = ' main.htm ',
' Header ' = ' header.htm ',
' LeftNav ' = ' leftnav.htm ');

The PHP code settings here $content to include the appropriate page content

$tpl->assign (' CONTENT ', $content);
$tpl->parse (' header ', ' header ');
$tpl->parse (' LeftNav ', ' leftnav ');
$TPL->parse (' main ', ' main ');
$tpl->fastprint (' MAIN ');

?>

Here we are using the popular Fasttemplate template class, but the basic idea is the same for many other template classes. First you instantiate a class, tell it where to look for the template file and which template file corresponds to which part of the page, then generate the page content, assign the result to the identifier of the content, and then parse each template file in turn, the template class will perform the necessary substitution operations, and finally output the parsing results to the browser.


This file is completely composed of PHP code, does not contain any HTML code, this is its biggest advantage. Now, PHP programmers can focus on writing code that generates page content, rather than worrying about how to generate HTML to properly format the final page.


You can use this method and the above file to construct a complete Web site. If the PHP code generates page content based on the query string in the URL, such as http://www.foo.com/example.php?article=099, you can construct a full magazine website accordingly.


It is easy to see that there is a second benefit to adopting a template. As shown in the example above, the navigation bar on the left side of the page is saved separately as a file, and we can simply edit this template file to change the navigation bar on the left side of all pages of the site.

http://www.bkjia.com/PHPjc/315436.html www.bkjia.com true http://www.bkjia.com/PHPjc/315436.html techarticle The PHP code is all saved to a separate file, which is the file that is actually called by the page URL. The Web server parses the file through the PHP engine and returns the results to the browser. ...

  • Related Article

    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.