Reserved variable usage analysis in PHP template engine smarty, template smarty_php Tutorial

Source: Internet
Author: User
Tags php template smarty template

Reserved variable usage analysis in PHP template engine smarty, template Smarty


This example describes the usage of reserved variables in the PHP template engine smarty. Share to everyone for your reference, as follows:

In Smarty, there are reserved variables that are not required to be allocated by the PHP script and can be used directly, i.e. without using $_tpl->assign (' var ', ' value ') to allocate.

1. Accessing the page request variables in the template

{$smarty. get.user} = = $_get[' user ']{$smarty. Post.user} = $_post[' user ']{$smarty. cookie.username} = = $_cookie[' Username ']{$smarty. session.username} = = $_session[' username ']{$smarty. server.remote_addr} = = $_server["remote_addr "]{$smarty. Env.path} = = $_env[' PATH ']{$smarty. Request.username} = $_request[' username ']

2. Accessing the constants and system constants defined in the PHP script in the template file

{$smarty. const.__file__}  Currently executing PHP file {$smarty. Const.const_var}  //Access define defined constants in PHP scripts

3. Get the current server time in the template file

Copy the code as follows: {$smarty. Now|date_format: "%y-%m-%d%h:%m:%s"} = = date in php script (' y-m-d h:i:s ', Time ())

4. configuration file access in the template

You can access the template variables in the configuration file by {$smarty. config. Configuration variable}. In this case, there are two ways to access the variables in the configuration file in the template: one, {#配置变量 #}, two, {$smarty. config, config variable}, if there is a region.

5. Get data captured by Smarty built-in function capture

The function of the capture function is to capture data from the template output and store it in a variable instead of outputting it to the page, and any data between {capture Name= "foo"} and {/capture} will be stored in the variable $foo, which is specified by the Name property. The variable is accessed by the $smarty. Capture.foo in the template, and if the Name property is not specified, the function defaults to use "default" as the parameter.

6. $smarty of reserved variables. foreach

$smarty. Foreach gets some information about the Foreach Loop array, such as the number of arrays, incrementing by +1 ..., about the use of $smarty. Foreach, refer to the previous article PHP template engine Smarty Built-in function foreach, Analysis of Foreachelse usage

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
    • PHP template engine Smarty built-in function foreach,foreachelse usage analysis
    • PHP template Engine Smarty Example of how a configuration file is used in template variables
    • 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/1119976.html www.bkjia.com true http://www.bkjia.com/PHPjc/1119976.html techarticle the reserved variable usage analysis in PHP template engine smarty, template Smarty This article describes the usage of reserved variables in the PHP template engine smarty. Share to everyone for your reference, as follows: ...

  • Related Article

    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.