Introduction to Smarty for Smarty Template Learning Notes

  • 2021-06-28 09:03:28
  • OfStack

1. Introduction

Smarty is a template PHP template engine written by PHP, which is the most famous PHP template engine in the industry.It separates logical code from external content and provides an easy-to-manage and easy-to-use way to logically separate PHP code that was originally mixed with HTML code.Simply put, the purpose is to separate the PHP programmer from the front-end, so that the PHP programmer can change the logic content of the program without affecting the front-end page design, and the front-end modification of the page will not affect the program logic of the program, which is especially important in multi-person projects.

2. What are the advantages of smarty?

a, Speed: Programs written with Smarty can achieve maximum speed improvement, which is relative to other template engine technologies.

b, Compiled: A program written in Smarty is compiled at run time into a non-template technology PHP file, which is a hybrid of PHP and HTML. WEB requests are converted directly to this file the next time the template is accessed, without template recompilation (without changes to the source program)

c, Caching technology: Smarty uses a caching technology that caches the HTML file that the user eventually sees into a static HTML page. When cache attribute of Smarty is set to true, the WEB request of the user is directly converted to this static HTML file during the cachetime period set by Smarty, which is equivalent to calling a static HTML file.

d, plug-in technology: Smarty can customize plug-ins.Plugins are actually just a few custom functions.

e, templates can use if/elseif/else/endif.Using a judgment statement in a template file is a convenient way to format the template.

3. However, the following should be noted when using smarty

a, content that needs to be updated in real time.For example, a stock display requires frequent updates to the data, and the use of smarty in this type of program can slow down template processing.

b, small project.Because small projects are simple and have both artists and programmers working on one project, using Smarty will lose some of the advantages of PHP's rapid development.

(PS: But for the specifications of the entire project, try using the template engine.As a matter of fact, development will be faster if you get used to it. These are the problems encountered by developers who don't have a custom template engine.)


Related articles: