The role of the configuration file in the template is to define variables for the front-end design page, which mainly controls the appearance of the template and has nothing to do with the PHP program. Steps: 1. use $ tpl-& gt; configs_dir & quot; Directory & quot; // to specify the directory where the configuration file is stored. 2. use & lt; in the template; {configs_loa... syntaxHig
The role of the configuration file in the template is to define variables for the front-end design page, which mainly controls the appearance of the template and has nothing to do with the PHP program.
Procedure:
1. use $ tpl-> configs_dir = "directory" // specify the directory where the configuration file is stored;
2. use <{configs_load file = "configuration file"}> in the template to load the f configuration file. if there is a region, use section = "region" to specify the region.
The purpose of setting a region is to call the configuration file variables of different regions for different files.
In the configuration file, "[region name]" is used to specify the region. other variables without the specified region are common variables, that is, each page can be used.
3. create a configuration file under the specified directory.
The following example demonstrates how to use an example: index. php in the main file calls index. tpl in the template file and sets the configuration file variable in index. tpl (unrelated to the PHP program)
Init. inc. php Smart template engine initialization file
Define ('root _ path', dirname (_ FILE _); // The website ROOT directory
Require ROOT_PATH. '/libs/Smarty. class. php'; // introduce the Smart template engine.
$ _ Tpl = new Smarty (); // Initialize an object
$ _ Tpl-> template_dir = ROOT_PATH. '/tpl/'; // reset the Template directory of the website.
$ _ Tpl-> compile_dir = ROOT_PATH. './com/'; // reset the website's compiling file directory
$ _ Tpl-> config_dir = ROOT_PATH. '/configs/'; // reset the configuration file directory of the website.
$ _ Tpl-> left_delimiter = '<{'; // reset the left delimiter of the website.
$ _ Tpl-> right_delimiter = '}>'; // reset the right delimiter of the website.
?>
Index. php
Require 'init. inc. php'; // introduce the template initialization file
Global $ _ tpl;
$ _ Tpl-> display ('index. tpl'); // load the template file
?>
Index. tpl configuration variables can be used in either of the following ways: 1. <{# configuration variable #}>; 2. <{$ smart. config. configuration variable}>
<{Config_load file = "view. conf" section = "one"}>
Use of configuration files in template variables
Aaaa |
Aaaa |
Aaaa |
Aaaa |
Aaaa |
Aaaa |
Aaaa |
Aaaa |
Aaaa |
Aaaa |
Aaaa |
Aaaa |
Display of region variables: <{# Aa #}> <{# Bb #}> <{# Cc #}> |
/Configs/view. conf configuration file
Border = 2
Tabw = 600
Tabh = 500
Bgcolor = yellow
Align = center
[One]
Colspan = 4
Aa = one section
[Two]
Bb = two section
[Three]
Cc = three section
Execution result ,:
From: Lee.'s column