This article mainly introduces the PHP template engine smarty configuration file in the template variable usage, combined with instance form analysis of configuration file variables specific use of steps and related skills, the need for friends can refer to the following
This article describes how the PHP template engine smarty configuration files are used in template variables. Share to everyone for your reference, as follows:
The role of a profile in a template is to define variables for the front-end design page, primarily to control the appearance of the template, regardless of the PHP program.
Steps to use:
1, using the $TPL->configs_dir= "directory"//Specify the directory of the configuration file;
2, in the template to use <{configs_load file= "configuration file"}> load F configuration file, if there is a region, you can use the section= "area" to specify the region
The purpose of setting the zone is to invoke the profile variables for different zones for different files.
In the configuration file, the zone is specified by "[zone name]", and the other variables that do not have a specified range are common variables, that is, each page can be used.
3. Create the configuration file under the specified directory.
The following is an example of the idea: the main file index.php call template file Index.tpl, set the configuration file variable in INDEX.TPL (not related to 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 Smart template engine $_tpl = new Smarty ();//Initialize an object $_tpl->template_dir = Root_path. ' /tpl/'; Reset the template directory for the site $_tpl->compile_dir = Root_path. /com/'; Reset the Web site's compiled files directory $_tpl->config_dir = Root_path. ' /configs/'; Reset the Web site's profile directory $_tpl->left_delimiter = ' <{';//reset the left delimiter of the site $_tpl->right_delimiter = '}> '; Reset the right delimiter for the site?>
index.php
<?php require ' init.inc.php ';//introduction of template Initialization file global $_tpl; $_tpl->display (' Index.tpl '); Loading template Files?>
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 the full path because it is specified in the initialization file, and section= "One" represents the load [ 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=2tabw=600tabh=500bgcolor=yellowalign=center[one]colspan=4aa=one Section[two]bb=two Section[three]cc=three Section
The results of the execution:
Summary: The above is the entire content of this article, I hope to be able to help you learn.