Configure and test the phpSmarty template engine

Source: Internet
Author: User
Tags php template
Smarty introduction smarty is a PHP template engine written using PHP. It provides the separation of logic and external content. Simply put, it aims to separate PHP programmers from artists, the programmer used to change the logic content of the program does not affect the page design of the artist. The re-modification of the page does not affect the program logic of the program.

Smarty introduction smarty is a PHP template engine written using PHP. It provides the separation of logic and external content. Simply put, it aims to separate PHP programmers from artists, the programmer used to change the logic content of the program does not affect the page design of the artist. The re-modification of the page does not affect the program logic of the program.

Smarty Introduction

Smarty is a PHP template engine written using PHP. It provides the separation of logic and external content. In short, it aims to separate PHP programmers from the artist, changing the program's logic does not affect the page design of the artist. Modifying the page does not affect the program's program logic, which is particularly important in projects that involve multiple partners.

Advantages:
1. Speed: Programs Written with smarty can achieve the maximum speed improvement, which is relative to other template engine technologies.
2. compilation type: a program written in smarty must be compiled into a non-template PHP file during runtime. This file adopts a mix of PHP and HTML, during the next template access, the WEB request is directly converted to this file, instead of re-compiling the template (without modifying the source program)
3. cache Technology: A cache technology used by smarty to cache the HTML file that the user sees as a static HTML page. When the cache attribute of smarty is set to true, during the cachetime period set by smarty, user WEB requests are directly converted to this static HTML file, which is equivalent to calling a static HTML file.
4. Plug-in technology: smarty can customize plug-ins. Plug-ins are actually some custom functions.
5. You can use if/elseif/else/endif in the template. Using judgment statements in the template file can easily rearrange the template format.

Disadvantages:
1. content to be updated in real time. For example, for a stock display, it needs to update data frequently. Using smarty for this type of program slows down the processing speed of the template.
2. small projects. Small projects because the project is simple and the artist and programmer have one project at the same time, using smarty will lose the advantage of rapid php development.


1. Install

Download the Smarty package. Decompress the package and change it to Smarty. In this example, D: \ wamp \ www \ Smarty.

2. Configuration
Modify include_path in the php. ini file
As follows:
; UNIX: "/path1:/path2"
; Include_path = ".:/php/shortdes"
; Windows: "\ path1; \ path2"
Include_path = "D: \ wamp \ www \ Smarty \ libs"
This example is modified in Windows.

Create a folder-MySmarty under the website directory. In this example, the path is D: \ wamp \ www \ Smarty \ MySmarty.
Create four sub-folders, templates, configs, templates_c, and cache.
Used
1. Storage Template
2. Store configuration information
3. Store compilation files

4. Store Cache

Set permissions for each folder.
Windows: Right-click and choose Properties> Security> Edit to modify user permissions.
Linux: chmod command

3. Test

Create the index. php file in the website directory. In this example, the path is D: \ wamp \ www \ Smarty \ MySmarty.

Index. php
 Template_dir = 'd: \ wamp \ www \ Smarty \ MySmarty \ templates '; $ smarty-> config_dir = 'd: \ wamp \ www \ Smarty \ MySmarty \ configs '; $ smarty-> cache_dir = 'd: \ wamp \ www \ Smarty \ MySmarty \ cache '; $ smarty-> compile_dir = 'd: \ wamp \ www \ Smarty \ MySmarty \ templates_c '; // $ smarty-> force_compile = true; $ smarty-> assign ("name", 'Tomorrow '); $ smarty-> display ('index. tpl ');?>

Create index. tpl in D: \ wamp \ www \ Smarty \ MySmarty \ templates

 Good, {$ name }!

Run index. php to test whether the settings are correct.


Recommended reference: here

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.