This article mainly introduces the configuration file data and retained data method of smarty template engine, and analyzes the smarty template engine with examples. Configuration file data and specific techniques for obtaining data have certain reference value. Friends in need can refer to it
The example in this article describes the configuration file data of smarty template engine and the method of retaining data. Share it with everyone for your reference. The details are as follows:
1. How to let the template directly retrieve data from the configuration file
1. Usage occasions
When a certain variable value does not want to be written directly into the program (allocated through smarty), it can be obtained through the configuration file.
2. Write configuration file
New folder: config
Create a new file name: my.ini or my.config
Content: key=value;
Example:
?
|
title="This is the title of the website."
|
Load configuration file: {config_laod file="path"}
1 2 |
{config_laod file="my.config"} ... |
?
1 2
|
{config_laod file="my.config"}
...
|
1 2 |
用户名:<{$smarty.get.username}> 密码:<{$smarty.get.password}> |
That is, how to obtain get/post/session/server data. These data are stored in arrays. Smarty encapsulates methods and can be obtained directly through smarty variables.
1. Obtain get data
Traditional method: get the get data first and then assign it to smarty. But smarty itself encapsulates the method, and you can get the data directly without allocation.
How to use it:
1 2 |
用户名:<{$smarty.post.username}> 密码:<{$smarty. post.password}> |
1 2
|
Username: <{$smarty.get.username}>
Password: <{$smarty.get.password}>
|
2. Obtain post data How to use it:
1 | Server name: <{$smarty.server.SERVER_NAME}> |