PHP Smarty learning

Source: Internet
Author: User
For more information about PHP's Smarty learning, see the documents on the network. you can use Smarty to perform a simple test:

1. decompress the Smarty file to the website directory, such as libs.

2. create the templates, templates_c, configs, and cache directories.

3. create a test page: index. php

Require "main. php ";

// $ Tpl defined in main. php


$ Tpl-> assign ("title", "webpage title for testing ");
$ Tpl-> assign ("content", "tested webpage content ");
// The above two rows can also be replaced by this line
// $ Tpl-> assign (array ("title" => "webpage title for testing", "content" => "webpage content for testing "));
$ Tpl-> display('index.htm ');
?>

4.create the template file index.htm under templates


  
  
  <{$ Title}>
  
  
<{$ Content}>
  
  

5. create main. php

/* If this addition is not added, an error is reported:

Notice: Undefined variable: _ SESSION in E: \ PHPnow-1.5.1 \ vhosts \ xxh.com \ libs \ Smarty. class. php on line 585

I don't know why

*/
Session_start (); // enable session
Include "libs/Smarty. class. php ";
Define ('_ SITE_ROOT', 'E:/PHPnow-1.5.1/vhosts/xxh.com '); // no diagonal lines at last
$ Tpl = new Smarty ();
$ Tpl-> template_dir = _ SITE_ROOT. "/templates /";
$ Tpl-> compile_dir = _ SITE_ROOT. "/templates_c /";
$ Tpl-> config_dir = _ SITE_ROOT. "/configs /";
$ Tpl-> cache_dir = _ SITE_ROOT. "/cache /";
$ Tpl-> left_delimiter = '<{';
$ Tpl-> right_delimiter = '}> ';
?>

6. Open index. php to test the Smarty.

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.