Getting started with configuring and using the Smarty environment and getting started with the smarty Environment

Source: Internet
Author: User
Tags smarty template

Getting started with configuring and using the Smarty environment and getting started with the smarty Environment

This article describes how to configure and use the Smarty environment. We will share this with you for your reference. The details are as follows:

Download Smarty (Here we use Smarty-2.6.26 as an example ). Decompress the downloaded file (the directory structure is quite complex ). Next we will show you how to install an instance.

(1) create a new directory named learn/Under the root directory, and create 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/, and config/in templates /.

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTDHTML 4.01

Create index. php and put this file under learn:

<? Phprequire 'smarty/libs/smarty. class. php '; $ smarty = new Smarty; // set the path of each directory. Here is the installation focus $ smarty-> template_dir = "smarty/templates "; $ smarty-> compile_dir = "smarty/templates/templates_c"; $ smarty-> config_dir = "smarty/templates/config "; $ smarty-> cache_dir = "smarty/templates/cache"; // The smarty template provides the high-speed cache function. If it is true, caching is enabled, however, the webpage may not be updated immediately. You can also use other methods to solve the problem $ smarty-> caching = false; $ smarty-> left_delimiter = "{#"; // Redefine the boundary because the default boundary "{}" is, when embedding a js script file in an html page to write code segments, the "{}" character is used. The custom boundary character can also be <{}>, $ smarty-> right_delimiter = "#}"; $ hello =" Hello World! "; // Value $ smarty-> assign (" hello ", $ hello); // reference the Template File $ smarty-> display ('index. tpl ');?>

(3) execute index. php to see Hello World! .

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.