PHP smarty Template engine configuration and testing

Source: Internet
Author: User
Tags php template smarty template
PHP smarty Template engine configuration and testing

Smarty Introduction

Smarty is a php template used to write a template engine, it provides a separation of logic and external content, in brief, the purpose is to use a PHP programmer with the Art of separation, the use of programmers to change the logic of the program content does not affect the design of the art page, The artist re-modifying the page does not affect program logic, which is especially important in a multi-person collaborative project.

Advantages:
1. Speed: The program written in Smarty can get the maximum speed improvement, which is relative to other template engine technology.
2. Compiled: The program written in Smarty is compiled into a non-template PHP file at runtime, this file is a mixture of PHP and HTML, the next time you access the template, the Web request directly into this file, Instead of recompiling the template (in case the source program has not changed)
3. Caching technology: Smarty chooses a caching technology that caches the HTML files the user eventually sees as a static HTML page, and when the cache property of the Smarty is set to True, The user's Web request is converted directly to this static HTML file during the Cachetime period set by Smarty, which is equivalent to calling a static HTML file.
4. Plug-in technology: Smarty can customize the plugin. Plugins are actually some of the custom functions.
5. If/elseif/else/endif can be used in the template. The template file can be easily reformatted by using a judgment statement.

Disadvantages:
1. Content that needs to be updated in real time. For example, like a stock display, it needs to update the data frequently, and this type of program uses Smarty to slow down the processing of the template.
2. Small project. Small project because the project is simple and the artist and programmer are in one person's project, using Smarty will lose the advantage of rapid development of PHP.


1. Installation

Download the Smarty package. Unzip and rename to Smarty and put it in the website directory, this example: D:\wamp\www\Smarty

2. Configuration
Modify Include_path in php.ini file
As follows:
; UNIX: "/path1:/path2"
; include_path = ".:/ Php/includes "
; Windows: "\path1;\path2"
include_path = "D:\wamp\www\Smarty\libs"
This example is modified under Windows, and Linux similarly

Create folder under Site Directory-mysmarty, this example path: D:\wamp\www\Smarty\MySmarty
and create 4 sub-folders under it Templates,configs,templates_c,cache
respectively for
1. Storage templates
2. Storing configuration information
3. Storing the compiled files

4. Storing the cache

Set permissions for each folder.
Windows: Right-click Properties--Security--Edit to modify user rights
LINUX:CHMOD directive

3. Testing

Create a index.php file in the Site Directory This example path 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 ');? >

Establish INDEX.TPL in D:\wamp\www\Smarty\MySmarty\templates

 
  OK, {$name}!

Run index.php and test the settings correctly.


Recommended reference: Here

  • Related Article

    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.