Implementation of constants that can be referenced in ecshop templates

Source: Internet
Author: User
Tags constant php tutorial smarty template

Implementation of constants that can be referenced in ecshop templates

Page request variable
The following are examples of access page request variables such as get, post, cookies, server, enviroment, and session variables.

For example, {$ smarty. server. SERVER_NAME} obtains the server variable,

{$ Smarty. env. PATH} obtains the path of the system environment variable, and {$ smarty. request. username}.

Get/post/cookies/server/env compound variable.

The variable {$ smarty. now} is used to access the current timestamp.
You can use the date_format regulator to format the output. For example, {$ smarty. now | date_format: "% Y-% m-% d % H: %

M: % S "}

{$ Smarty. const}
You can directly access PHP constants. For example, {$ smarty. const. _ MY_CONST_VAL}

{$ Smarty. capture}
You can use the {$ smarty} variable to access the output captured by the {capture}... {/capture} structure.

{$ Smarty. config}
The variable {$ smarty} can access the loaded config variable.
For example, {$ smarty. config. foo} indicates {# foo #}.

{$ Smarty. section}, {$ smarty. foreach}
The {$ smarty} variable can be used to access the attributes of the 'core' and 'foreach' loops.

{$ Smarty. template}
Displays the name of the currently processed template.

{$ Smarty. version}
Display the version of the smarty Template

{$ Smarty. ldelim}
Show left separator

{$ Smarty. rdelim}
Show right separator

 

To add the reference constant function to the ecshop template this time, you only need to add two lines of code to the make_var () function.
Copy the code as follows:

Function make_var ($ val)
{
If (strrpos ($ val, '.') = false)
{
If (isset ($ this-> _ var [$ val]) & isset ($ this-> _ patchstack [$ val])
{
$ Val = $ this-> _ patchstack [$ val];
}
$ P = '$ this-> _ var [''. $ val.'']';
}
Else
{
$ T = explode ('.', $ val );
$ _ Var_name = array_shift ($ t );
If (isset ($ this-> _ var [$ _ var_name]) & isset ($ this-> _ patchstack [$ _ var_name])
{
$ _ Var_name = $ this-> _ patchstack [$ _ var_name];
}
If ($ _ var_name = 'smarty ')
{
If ($ t [0] = 'const '){
Return strtoupper ($ t [1]);
}
$ P = $ this-> _ compile_smarty_ref ($ t );
}
Else
{
$ P = '$ this-> _ var [''. $ _ var_name.'']';
}
Foreach ($ t AS $ val)
{
$ P. = '[''. $ val.'']';
}
}
Return $ p;
}

Lines 21-23 are newly added, which allows you to reference the definition in the php Tutorial through {$ smarty. const. Constant} in the template file.

Constant.
Copy the code as follows:

If ($ t [0] = 'const '){
Return strtoupper ($ t [1]);
}

In fact, the template engine is not complex in principle. It just replaces some template labels with functions, variables, and syntax structures in php.

.

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.