Improved template php explanatory template phplib_php Tutorial

Source: Internet
Author: User

Before explaining the use of PHP explanatory template phplib, let's explain why the template system using PHP tags continues to improve. In fact, this is mainly because the PHP tag is not convenient for artists. They prefer to use this visual label directly, such as {title}.

First of all, we have modified our previous example to use a visual label to handle it. The first step, change the shownews.php to Shownews.tpl, the inside of the PHP tag into a visual label, SHOWNEWS.TPL code as follows:

  1. < html>
  2. < head>
  3. < title> Show News < /title>
  4. < /head >
  5. < body>
  6. {title}
  7. < /body >
  8. < /html >

The second step, how to achieve the effect of listnews.php? Actually very simple, I just have to replace {title} to not be OK? So, the code for the modified listnews.php is as follows:

 
  
  
  1. < ?
  2. Include (' getnews.php ');
  3. Get Data
  4. Echo Str_replace (' {title} ',
  5. $news, file_get_contents
    (' Shownews.tpl '))
  6. ?>

In fact, PHP explanatory template phplib principle is exactly the way! For example, we want to use Phplib to achieve the above function, we just need to modify listnews.php. The following code is modified:

 
  
  
  1. < ?
  2. Include (' getnews.php ');
  3. Get Data
  4. Include (' template.class.php ');
  5. $ T = New Template ();
  6. $t- > set_file (' Shownesw,
    ' Shownews.tpl ');
  7. $t- > Set_var (' News ', $news);
  8. $t- > Parse (' Out ', ' shownesw ');
  9. $t- > P (' out ');
  10. ?>

In addition to the PHP explanatory template phplib area, you can check the corresponding manual.


http://www.bkjia.com/PHPjc/446061.html www.bkjia.com true http://www.bkjia.com/PHPjc/446061.html techarticle before explaining the use of PHP explanatory template phplib, let's explain why the template system using PHP tags continues to improve. In fact, this is mainly because the PHP tag for artists ...

  • 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.