1, What is a template engine
The template engine (here specifically refers to the template engine used for Web development) is to make the user interface Generated by the separation of business data (content), it can generate documents in a specific format, and the template engine used for the website will generate a standard HTML document. The template engine does not belong to a specific technical field, it is a cross-domain and cross-platform concept. There is a template engine under Asp, there is a template engine under PHP, there is also a template engine under C#, and even JavaScript and WinForm development use template engine technology. The template of the template engine is an ordinary text file and does not need a special extension. .html .htm .twig can be used. Variables and expressions in the template will be parsed and replaced at runtime, and tags will control the logic of the template.
2, smarty template engine
Smarty is a php template engine. More precisely, it separates the logic program and external content, providing an easy-to-manage method. It can be described as the application programmer
# and the artist play different roles, because in most cases, they cannot be the same person. For example, if you are creating a web page for browsing news, the news title, tag
column, author and content are all content elements, and they do not include how they should be presented. In Smarty's program, these are ignored. Template designers edit templates and use a combination of
html tags and template tags to format the output of these elements (html tables, background colors, font sizes, style sheets, etc.). One day the programmer wanted to change the way of article retrieval (also
, which is a change in program logic). This change does not affect template designers, and content will still be output to the template accurately. Similarly, if one day the artist gets too much and wants to completely redo the interface, it will not
affect the program logic. Therefore, programmers can change the logic without rebuilding the template, and template designers can change the template without affecting the logic. smarty doesn't try to convert logic
Completely separate from the template. If the logic program is used strictly for page presentation, then it will not cause problems in the template. Here’s a suggestion: Keep application logic away from templates, and page presentation
logic away from application logic. This will make content easier to manage and programs easier to upgrade in the future.
3, Features of smaty engine
Template compilation. To reduce overhead, Smarty converts templates into comparable PHP scripts by default, making subsequent calls faster. Smarty is also very smart and can be recompiled after the content changes.
cache. Smarty also provides the optional feature of caching templates. The difference between caching and compilation is that supporting caching not only generates cached content, but also prevents the execution of individual logic. For example, you can specify a cached document lifetime, such as 5 minutes, during which database queries related to the template can be ignored.
Highly configurable and extensible. Smarty's object-oriented architecture allows its default behavior to be modified and extended. Additionally, configurability was a design goal from the beginning, providing users with great flexibility to customize Smarty's behavior through built-in methods and properties.
Safety. Smarty provides many security features to protect server and application data from intentional or unintentional destruction by designers.