PHP uses Smarty: Reserved variables in Smarty _php tutorial

Source: Internet
Author: User
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} accesses define-defined constants in PHP scripts

3. Get the current server time in the template file

{$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 through $smarty.capture.foo in the template, and if the Name property is not specified, the function defaults to use "default" as the argument


Excerpt from: Lee's Column

http://www.bkjia.com/PHPjc/478571.html www.bkjia.com true http://www.bkjia.com/PHPjc/478571.html techarticle in Smarty, there are reserved variables that are not required to be allocated by PHP scripts and can be used directly, i.e. without using $_tpl-assign (Var,value) to allocate. 1, in the template to access the page please ...

  • 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.