Use Smarty 3 in PHP: reserved variable in Smarty. There are some reserved variables in Smarty, which can be directly used without the PHP script for allocation, that is, $ _ tpl-assign (var, value) for allocation. 1. visit the page in the template. there are some reserved variables in Smarty. they can be directly used without being allocated by the PHP script, you do not need to use $ _ tpl-> assign ('var', 'value') for allocation.
1. variables used to access the page request 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. access the constants and system constants defined in the PHP script in the template file.
{$ Smarty. const. _ FILE __} current PHP FILE
{$ Smarty. const. CONST_VAR} accesses the constant defined by define in the PHP script.
3. get the time of the current server in the template file
{$ Smarty. now | date_format: "% Y-% m-% d % H: % M: % S" }== date ('Y-m-d H: I: s ', time ())
4. access the configuration file in the template
You can use {$ smarty. config. configuration variable} to access the Template variables in the configuration file. In this way, there are two methods to access the variables in the configuration file in the Template: 1. {# configuration variable #}; 2. {$ smarty. config. configuration variable}. this is also true if there is a region.
5. obtain the data captured by the Smarty built-in function capture.
The capture function captures the data output from the template and stores the data in a variable instead of outputting the data to the page, any data between {capture name = "foo"} and {/capture} is stored in the variable $ foo, which is specified by the name attribute. Access the variable through $ smarty. capture. foo in the template. if the name attribute is not specified, the function uses "default" as the parameter by default.
From: Lee.'s column
There are some reserved variables, which can be directly used without the PHP script for allocation, that is, $ _ tpl-assign (var, value) for allocation. 1. visit the page in the template...