Smarty instance tutorial

Source: Internet
Author: User
Tags php template
Smarty instance tutorial (1) 1. what is smarty? Smarty is a PHP template engine written by the application PHP. It provides the logic and external content respectively. In short, the goal is to separate the application PHP programmers from the artist, application Programmer transformation process

Smarty instance tutorial (1)
1. what is smarty?
Smarty is a PHP template engine written by the application PHP. It provides the logic and external content respectively. In short, the goal is to use PHP programmers to share the same job score with the US.
The logic content of the application programmer's transformation program does not affect the page design of the artist, and the art's re-correction page does not affect the program logic.
Is particularly important.

II. Advantages of smarty:
1. speed: programs written with smarty can achieve maximum speed improvement, which is relative to other template engine skills.

2. compilation type: a program written using smarty must be compiled into a PHP file with non-template skills during runtime. this file uses a mix of PHP and HTML methods. next visit
When asked about the template, the WEB request is directly converted to this file, instead of re-compiling the template (if the source program is not corrected)

3. cache skills: smarty uses a caching technique that caches the HTML files that users can ultimately see into a static HTML page. when the cache attribute of smarty is set
If it is set to true, the user's WEB request is directly converted to this static HTML file during the cachetime period set by smarty, which is equivalent to calling a static HTML file.

4. plug-in skills: smarty can customize plug-ins. Plug-ins are actually some custom functions.

5. You can apply if/elseif/else/endif to the template. You can easily rearrange the template pattern by applying the judgment statement in the template file.

3. deploy smarty:

1. content to be updated in real time. For example, for a stock display, it often needs to update the data. This type of program application smarty slows down the processing speed of the template.

2. small projects. Small projects because the project is simple and the artist and the programmer have a one-person project, the application smarty will lose the advantages of php development agility.

IV. install smarty:

Install the smarty environment: php version 4.06 or later.

The method for installing smarty is very simple.Http://samrty.php.netDownload all files in the LIB
Copy to the comm directory to complete basic installation.

For other advanced installation methods, see the manual.

5. Application of smarty in the template:

This section describes the applications of smarty through several instances. The smartytemplate.tplto be used to identify the Common Application. some people are easy to use, and can directly write the extended name into .html.
. In this article, the smarty scale statement is used: the. tpl is used as a smarty template.

PHP code :--------------------------------------------------------------------------------

Instance 1:

Let's look at a simple example.
========================================================== ==================
Index. tpl
========================================================== ==================

{* Display is the comment content in the "X" contained in the smarty variable identifier *}
{Include file = 'header. tpl '} {* page header *}
Hello everyone, my name is {$ name}. You are welcome to browse my smarty learning materials.

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: 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.