Get Smarty

Donate

Donate Bitcoin Bitcoin
Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Buy cheap eyeglasses from Cheapglasses123.com and save up to 80%.

Buy prescription glasses from www.australiaglasses.com and save.

Cheap Glasses Now On Sale at GlassesPeople.com. Starts At $7.95.

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Brautkleider auf Topwedding.de

Find free files to download on allwhatyouwant.net

Looking For Affordable Wedding Dresses 2015 at Best Prices On TDBridal.com

Shop high quality cheap prom dresses on Dresswe.co.uk

Buy New Arrival Cheap Prom Dresses 2015 at JDBRIDAL Prom Dress Store

Advertisement

{$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}

   

Note

由于历史愿意,{$SCRIPT_NAME}变量会作为 {$smarty.server.SCRIPT_NAME}的缩写。


<a href="{$SCRIPT_NAME}?page=smarty">click me</a>
<a href="{$smarty.server.SCRIPT_NAME}?page=smarty">click me</a>

Note

虽然Smarty提供了较方便直接访问PHP超全局变量的方法,但必须谨慎使用。 直接访问超全局变量会弄乱应用程序底层代码和模板语法。 最佳的实践是从PHP将需要的变量对模板进行赋值再使用。

{$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}

Note

虽然Smarty有较方便直接访问PHP常量的方法。 但这通常会弄乱应用程序底层代码和模板语法。 最佳的实践是从PHP将需要的变量对模板进行赋值再使用。

{$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等等。

Note

{$smarty.foreach}变量在新的{foreach} 语法中已经不再使用。 但仍然支持Smarty 2.x 风格的 foreach 语法。

{$smarty.template}

返回当前的模板名称(不带目录名)。

{$smarty.template_object}

返回当前模板对象。

{$smarty.current_dir}

返回当前模板的目录名称。

{$smarty.version}

返回编译当前模板的Smarty版本。


<div id="footer">由 Smarty {$smarty.version} 引擎驱动</div>

{$smarty.block.child}

返回子模板提供的区块代码。 参见模板继承

{$smarty.block.parent}

返回父模板提供的区块代码。 参见模板继承

{$smarty.ldelim}, {$smarty.rdelim}

用于显示左定界符和右定界符。等同于 {ldelim},{rdelim}

参见 赋值变量配置变量

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 15 plus 3? (Are you human?)

Advertisement