This example describes how to use the configuration file of the PHP template engine smarty in the template variable. Share to everyone for your reference, specific as follows:
The role of a profile in a template is to design the page definition variable for the front end, primarily to control the appearance of the template, regardless of the PHP program.
Use steps:
1, the use of $TPL->configs_dir= "directory"//designated configuration files stored in the directory;
2, in the template to use <{configs_load file= "configuration file"}> load F configuration file, if there are areas, you can use section= "area" to specify the area
The purpose of setting up a zone is to invoke a different zone's profile variable for different files.
In a configuration file, you specify a range by [zone name], and other variables that do not have a specified range are shared variables, that is, each page can be used.
3, set up the configuration file in the specified directory.
The following is illustrated with an example: the main file index.php call the template file Index.tpl and set the profile variable in INDEX.TPL (regardless of the PHP program)
init.inc.php Smart template engine initialization file
<?php
define (' Root_path ', DirName (__file__));//Site root directory
require Root_path. ' /libs/smarty.class.php '; Introduction of the Smart template engine
$_tpl = new Smarty ();//Initialize an object
$_tpl->template_dir = Root_path. ' /tpl/'; Reset the template directory for the Web site
$_tpl->compile_dir = Root_path. '. /com/'; Reset the compilation file directory of the Web site
$_tpl->config_dir = root_path. ' /configs/'; Reset the profile directory of the Web site
$_tpl->left_delimiter = ' <{';//reset the left delimiter of the Web site
$_tpl->right_delimiter = '}> '; Reset the right delimiter of the Web site
?>
index.php
<?php
require ' init.inc.php ';//introduction of template Initialization file
global $_tpl;
$_tpl->display (' Index.tpl '); Load template file
?>
There are two ways to use INDEX.TPL configuration variables:
First, <{#配置变量 #}>;
Second, <{$smart. config. Configuration variable}>
<{config_load file= "view.conf" section= "one"}> <!--view.conf file cannot write full path because it is already specified in the initialization file, and section= "one" represents loading [ One] area--> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
/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 results, as shown in the figure:
More about PHP Interested readers can view the site topics: "Smarty Template Primer Tutorial", "PHP Template Technology Summary", "PHP based on PDO Operation Database Skills summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", " Introduction to PHP Basic Grammar, "Introduction to PHP object-oriented programming", "PHP string (String) Usage Summary", "Php+mysql Database Operations Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on Smarty template.