保留变量
{$smarty} 保留變量
可以通過PHP的保留變量?{$smarty}來訪問一些環境變量。 下面是這些變量的列表:
頁面請求變量
頁面請求變量如$_GET,?$_POST,?$_COOKIE,?$_SERVER,?$_ENV?和?$_SESSION?可以通過下面的方式來使用:
Example?4.8.?顯示頁面請求變量
{* display value of page from URL ($_GET) http://www.example.com/index.php?page=foo *}
{$smarty.get.page}{* display the variable "page" from a form ($_POST['page']) *}
{$smarty.post.page}{* display the value of the cookie "username" ($_COOKIE['username']) *}
{$smarty.cookies.username}{* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*}
{$smarty.server.SERVER_NAME}{* display the system environment variable "PATH" *}
{$smarty.env.PATH}{* display the php session variable "id" ($_SESSION['id']) *}
{$smarty.session.id}{* display the variable "username" from merged get/post/cookies/server/env *}
{$smarty.request.username} {$smarty.now}
當前的時間戳?可以通過{$smarty.now}來獲取。 時間戳是從1970年1月1日開始計算到當前的秒數。 當前時間戳可以被date_format?修飾器使用并顯示。 注意:在每次使用該變量時都會調用time()函數。 比如說一個程序花了三秒來執行,在開頭和結束時都調用了$smarty.now,那么這兩個數值將差三秒。
{* use the date_format modifier to show current date and time *}
{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'} {$smarty.const}
直接訪問PHP的常量。參見?smarty 常量.
<?php
// the constant defined in php
define('MY_CONST_VAL','CHERRIES');
?> 在模板中顯示常量
{$smarty.const.MY_CONST_VAL} {$smarty.capture}
Smarty內置函數?{capture}..{/capture}可以捕獲其中的代碼輸出。 通過{$smarty.capture}變量可以使用這些輸出的代碼。 參見?{capture}函數。
{$smarty.config}
{$smarty.config}變量可以獲取?配置變量。?{$smarty.config.foo}可獲取設置變量的{#foo#}。參見?{config_load}。
{$smarty.section}
{$smarty.section}變量是{section}?循環中的屬性。 它提供了一些很有用的值,如.first,?.index等等。
{$smarty.template}
返回當前的模板名稱(不帶目錄名)。
{$smarty.template_object}
返回當前模板對象。
{$smarty.current_dir}
返回當前模板的目錄名稱。
{$smarty.version}
<div id="footer">由 Smarty {$smarty.version} 引擎驅動</div> 返回編譯當前模板的Smarty版本。
{$smarty.block.child}
返回子模板提供的區塊代碼。 參見模板繼承。
{$smarty.block.parent}
返回父模板提供的區塊代碼。 參見模板繼承。
{$smarty.ldelim}, {$smarty.rdelim}
用于顯示左定界符和右定界符。等同于?{ldelim},{rdelim}。
參見?賦值變量?和?配置變量
?
?
?
轉載于:https://www.cnblogs.com/gaocy/p/8167186.html
總結
- 上一篇: 盆腔炎导致输卵管不通
- 下一篇: css 定位及遮罩层小技巧