Get page parameters in the Smarty template

Source: Internet
Author: User
Tags smarty template

{$smarty} The reserved variable does not need to be allocated from a PHP script, it is an array type variable that can be accessed directly in the template, and is typically used to access some special template variables. For example, access the page request variables directly in the template, get the time stamp to access the template, direct access to the constants in PHP, read variables from the configuration file, and so on. Some of the accesses in this reserved variable are described below.

1. Accessing page request variables in a template

In PHP scripts, we can get the data that the client submits to the server in different ways through the Super Global array $_get, $_post, $_request, or by $_cookie or $_session to track variables between multiple scripts, or through $_env and $_ Server gets the system environment variable. If you need these arrays in the template, you can call the Assign () method in the Smarty object to assign to the template. However, in the Smarty template, these page request variables can be accessed directly through the {$smarty} reserved variable. The examples used in templates are as follows:

1. {$smarty. get.page} {* php mode: $_get["page"] *} 2.           {$smarty. Post.page} {* PHP Mode: $_post["page"] *} 3. {$smarty. cookies.username} {* php mode: $_cookie["username"] *} 4.          {$smarty. Session.id}  {* PHP mode: $_session["id"] *} 5. {$smarty. server.server_name} {* php mode: $_server["SERVER_NAME"] *} 6.            {$smarty. Env.path} {* PHP mode: $_env["PATH"]*} 7. {$smarty. request.username} {* php mode: $_request["username"] *}

2. Accessing variables in PHP in a template

In PHP script there are system constants and custom constants two, the same two constants in the Smarty template can also be accessed, and do not need to be allocated from PHP, as long as the {$smarty} reserved variable can directly output the value of the constant. An example of an output constant in a template is shown below:

1. {$smarty. const._my_const_val} {* Output the custom constants in PHP script *} 2.        {$smarty. const.__file__} {* Output system constants directly by preserving variable arrays *}


Get page parameters in the Smarty template

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.