Smarty 内置变量

{* 显示URL中的page值($_GEThttp://www.example.com/index.php?page=foo *}
{$smarty.get.page}

{* 显示来自一个表单的"page"变量($_POST['page'])*}
{$smarty.post.page}

{* 显示COOKIE变量"username"的值($_COOKIE['username'])*}
{$smarty.cookies.username}

{* 显示服务器变量"SERVER_NAME"($_SERVER['SERVER_NAME'])*}
{$smarty.server.SERVER_NAME}

{* 显示系统环境变量"PATH" *}
{$smarty.env.PATH}

{* 显示PHP会话变量"id"($_SESSION['id'])*}
{$smarty.session.id}

{* 显示变量"username",不论来自get/post/cookies/server/env *}
{$smarty.request.username}

注意:基于历史原因,{$SCRIPT_NAME}还可以被直接存取,尽管{$smarty.server.SCRIPT_NAME}是推荐的存取该值的方法。

    click me
    click me

{$smarty.now}

    当前的时间戳可以由{$smarty.now}来存取。返回值反映了自从所谓的元年(1970年1月1日)以来所经过的秒数,从而可以直接传递给日期格式修饰符进行显示。注意每次调用时都会调用time()函数。例如,一个脚本用了3秒执行完毕,那么在该脚本的开始和结束时所调用的$smarty.now将显示3秒的差异。

{* 使用date_format修饰符来显示当前日期和时间 *}
{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'}

{$smarty.const}

    可以直接访问PHP常量值。参见Smarty常量。

// the constant defined in php
define('MY_CONST_VAL','CHERRIES');
?>

    在模板中输出该常量:

{$smarty.const.MY_CONST_VAL}

{$smarty.capture}

    通过内建的{capture}..{/capture}函数而捕获的模板输出可以由{$smarty.capture}访问。更多信息请参见{capture}页。
{$smarty.config}

    {$smarty.config}变量可以用来访问调入的配置变量。{$smarty.config.foo}是{#foo#}的等同用法。更多信息请参见{config_load}页。
{$smarty.section},{$smarty.foreach}

{$smarty.section}和{$smarty.foreach}变量分别用来访问{section}和{foreach}循环属性。它们有一些非常有用的值,如.first,.index等。
{$smarty.template}

    返回当前处理的模板名。下面的例子展示了container.tpl和它包含的banner.tpl,各自都有{$smarty.template}变量。

Main container is {$smarty.template}
{include file='banner.tpl}

    将输出:

Main page is container.tpl
banner.tpl

{$smarty.version}

    返回编译模板使用的Smarty版本。

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

这些变量用来打印左分隔符和右分隔符,类似{ldelim},{rdelim}。

原文地址:https://www.cnblogs.com/lechie/p/2383237.html