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