Smarty template quick entry

Source: Internet
Author: User
0. introduction in the PHP world, there have been a variety of template classes, but in terms of efficacy and speed, Smarty is still in the leading position, because Smarty is relatively powerful, therefore, the application is a little more complex than some other template classes. Now 0. IntroductionIn the PHP world, there have been a variety of template classes, but in terms of efficacy and speed, Smarty is still in the leading position, because Smarty is relatively powerful, therefore, the application is a little more complex than some other template classes. Now it takes 30 minutes for you to enter the door quickly. 1. InstallationFirst open the webpage http://smarty.php.net/download.php and download the latest smarty. Decompress the downloaded file (the directory structure is quite complex ). Next, I will demonstrate how to install an instance.

(1) I created a new directory learn/under the root directory, and then created a directory named smarty/In learn /. Copy the libs/from the extracted directory to smarty/, create the templates directory in smarty/, and create cache/, templates/, templates_c/, config /, for example:

 

(2) create a new template file: index. tpl. Place the file in the learn/smarty/templates Directory. the code is as follows:

Smarty{$ Hello}

Create index. php and put this file under learn:

$ Smarty-> template_dir = 'smarty/templates/templates ';

$ Smarty-> compile_dir = 'smarty/templates/templates_c ';

$ Smarty-> config_dir = 'smarty/templates/config ';

$ Smarty-> cache_dir = 'smarty/templates/cache ';

// The smarty template has the high-speed cache function. If this parameter is set to true, caching is enabled, but the title of the webpage is not updated immediately, of course, you can also solve $ smarty-> caching = false; $ hello = 'Hello World! '; // Value $ smarty-> assign ('hello', $ hello); // reference the template file $ smarty-> display ('index. tpl');?> (3) execute index. php to see Hello World! . II. AssignmentIn the template file, replace the value with braces {}, and add the $ sign before the value. For example, {$ hello }. This can be an array, for example, {$ hello. item1}, {$ hello. item2 }... In the PHP source file, only a simple function assign (var, value) is required ). A simple example: *. tpl:

Hello, {$ exp. name }! Good {$ exp. time}

*. Php:

$ Hello [name] = "Mr. Green ";

$ Hello [time] = "morning"; $ smarty-> assign ("exp", $ hello); output:

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.