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