PhpSmarty template engine configuration and testing

Source: Internet
Author: User
Tags php template
Introduction to the phpSmarty template engine configuration and testing Smarty smarty is a PHP template engine written in PHP. It provides the separation of logic and external content, the purpose is to use PHP programmers to separate the programmers from the artists. Changing the logic content of the program by the programmers will not affect the webpage design of the artist. modifying the page by the artist will not affect the configuration and testing of the php Smarty template engine.

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.