I haven't used Smarty for a project for a long time. Today, I suddenly want to modify some of my website's content, because my website was made a long time ago using the smarty template engine, I felt I had to search for the answer on the Internet in some places. It seems that the long-lost smarty has been getting unfamiliar, so I have to study it quickly. Summarize the reserved variables of the Smarty template for future use.
The reserved variable {$ smarty} is a special variable that can be directly accessed in the template and does not need to be allocated from the PHP script.
{$ Smarty. get}, {$ smarty. post}, and so on are used to access the page request variables. The main page request variables include get, post, cookies, server, enviroment, and session variables. For example, {$ smarty. server. SERVER_NAME} gets the server variable, {$ smarty. env. PATH} obtains the path of the system environment variable {$ smarty. request. password} obtains the compound variable of get/post/cookies/server/env.
{$ Smarty. ldelim} and {$ smarty. rdelim} are used to display the Left and Right separators currently in use.
{$ 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"}. Output Format: 07:19:09
{$ Smarty. const} directly accesses PHP constants. for example, {$ smarty. const. _ FILE __} is equivalent to the _ FILE _ constant in php. Of course, you can also access custom constants.
{$ Smarty. capture} can output the data in the {capture} .. {/capture} tag through {$ smarty. capture. name. For detailed usage of capture, refer to http://www.phpernote.com/php-template-framework/43.html
The {$ smarty. config} {$ smarty} variable can access the loaded config variable. Note that the page template must first load a variable similar to {config_load file = "web. conf "}. For example, {$ smarty. config. pageTitle} indicates {# pageTitle #}.
{$ Smarty. section} and {$ smarty. foreach} can access the attributes of the 'secure' and 'foreach' loops.
{$ Smarty. template} displays the name of the currently processed template.
{$ Smarty. version} displays the version number of the currently used smarty template engine.
Articles you may be interested in
- Use php functions in the smarty template and how to use multiple functions for a variable in the smarty Template
- Add the latest tag to the information in the smarty Template
- Smarty template variable operator Summary
- How to generate a random number in the smarty Template
- Extension of the for loop in the smarty Template
- How to Use variables in smarty include file
- How to Use constants defined by define in a program in a smarty Template
- Summary of common system variables in Thinkphp templates