The smarty template engine obtains data from the configuration file. The smarty template engine obtains data from the configuration file. This document describes how the smarty template engine obtains data from the configuration file. For your reference, the smarty template engine obtains data from the configuration file.
This example describes how the smarty template engine obtains data from the configuration file. Share it with you for your reference. The details are as follows:
If you do not want to write a variable value to a program, you can write the variable to the configuration file and obtain it (common configuration styles ).
Step 1: first write a configuration file, such as db. conf of the database. you can write the configuration file with the suffix conf at will, and db. ini can also be used. The format of the content in the file must be fixed: key = "value". do not add a semicolon or a semicolon to the end of each line. you can directly return to China for a line break, for example:
Configuration File: db. conf
The code is as follows:
Host = "localhost"
Username = "root"
Password = "123456"
Db_name = "liuyan"
Template File: temp. tpl
Use {config_load file = "db. conf"} to introduce the file. Note: If you write a relative path, you should refer to the Accessed page. For example, temp. tpl is stored in the templates Directory, db. conf is placed on the same layer as the templates directory, but because of the file index accessed by the browser. php and db. conf is on the same layer. Therefore, when referencing, write {config_load file = "db. conf "}.
The code is as follows:
{Config_load file = "db. conf "}
Smarty variable operation, obtained from the configuration file
{# Host #}
{# Username #}
Browser access: index. php
Unlike getting variable data from php, assign allocation is not required here, but directly loaded in the template file.
The code is as follows:
<? Php
// Create a smarty object
Require_once ("./libs/Smarty. class. php ");
$ Smarty = new Smarty ();
$ Smarty-> display ("index. tpl ");
?>
I hope this article will help you design your smarty program.
Examples in this article describes how the smarty template engine obtains data from the configuration file. Share it with you for your reference...