Install and tune the Smarty3 module of php

Source: Internet
Author: User
Tags smarty template
: This article describes how to install and tune the Smarty3 module of php. For more information about PHP tutorials, see. When using the Smarty template, in order to split the user interface and business data

Install Smarty, official download URL: http://www.smarty.net/download.php

After decompression, you only need to copy the "libs" folder in the folder to the root directory.


In libs, only the Smarty. class. php class php is used.

Create the file to be used in the root directory


Here, tpls: Template directory, coms: generated Directory. during development, this directory should not be placed under the root directory of the web server.

Create a demo.html file under the tplsdirectory, which is a presentation layer interface

<{ $title }>   <{$content}>
<{$content}>
<{$content}>
《script》if(true){alert(new Date());}《script》

In init. inc. php, it is used to store php initialization code.

Similarly, you must set the template file storage directory and compilation Directory. to prevent conflicts with spaces, we can modify the delimiters.

It should be emphasized that the fixed Directory of the specified output can be called not only in the root directory, but also in the external directory.

 SetTemplateDir (ROOT. "/tpls")-> setCompileDir (ROOT. "/coms"); // specify the compiling Directory // modify the delimiter to prevent conflicts with spaces $ smarty-> auto_literal = false; // The default value is true, false does not conflict with spaces $ smarty-> left_delimiter = "<{"; $ smarty-> right_delimiter = "}> ";

Demo. php is the main file, mainly using the assign () method to implant variables into the template, and then using the display () method to output web pages

 assign("title","11111111");    $smarty->assign("content","2222222222");    $smarty->display("demo.html");

The basic usage of Smarty is like the above, but this is only a small part of Smarty. Smarty is a very powerful template.

The above describes how to install and tune the Smarty3 module of php, including some content. I hope my friends who are interested in the PHP Tutorial will be helpful.

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.