PHP template engine smarty of configuration files in template variables, examples of how to use the template smarty_php tutorial

Source: Internet
Author: User
Tags php template smarty template

PHP template engine smarty configuration file in template variables using the method example, template Smarty


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"}>
 
 
  
 <title>The use of configuration files in template variables</title>    
 
 
Aaaa Aaaa Aaaa Aaaa
Aaaa Aaaa Aaaa Aaaa
Aaaa Aaaa Aaaa Aaaa
Display of area variables: <{#aa #}>
<{#bb #}>
<{#cc #}>

/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:

More about PHP related content readers can view the topic: "Smarty Template Primer Basic Tutorial", "PHP Template Technology Summary", "PHP based on PDO Operation Database Skills summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", " PHP Basic Grammar Introductory tutorial, PHP Object-oriented Programming primer, PHP string usage Summary, PHP+MYSQL database Operations Primer and PHP Common database operations Tips Summary

It is hoped that this article will be helpful to everyone based on smarty template PHP program design.

Articles you may be interested in:

    • PHP template engine Smarty built-in functions
    • PHP template engine Smarty built-in variable mediator usage
    • PHP template engine smarty custom variable mediator usage
    • Analysis of the usage of reserved variables in PHP template engine Smarty
    • PHP template engine Smarty built-in function foreach,foreachelse usage analysis
    • Example of how variables are used in PHP template engine Smarty
    • Smarty how the template engine obtains data from PHP
    • thinkphp How to use the Smarty template engine
    • A method of generating random numbers in the PHP template engine smarty and an explanation of the math function
    • Summary of cache Usage for PHP template engine Smarty
    • 6 Tips for PHP smarty template engine
    • [PHP] Template engine Smarty Introduction
    • PHP template engine Smarty built-in functions section,sectionelse usage

http://www.bkjia.com/PHPjc/1119978.html www.bkjia.com true http://www.bkjia.com/PHPjc/1119978.html techarticle php template engine smarty of the configuration file in the template variable using the method example, template Smarty This article describes the PHP template engine smarty configuration file in the template variable use method. ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.