Get Smarty


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 glasses from and save up to 80%.

Where to buy prescription glasses? is your best choice!

Visit for cheap soccer cleats, sneakers and Soccer Jerseys updates



display() — 显示


void display(string template,
             string cache_id,
             string compile_id);

显示模板。如果希望返回而并非显示当前模板的内容,请使用fetch()。 该函数需要指定一个合法的模板资源的类型和路径。 第二个可选的参数$cache_id设置缓存,详情参见 缓存

As an optional third parameter, you can pass a $compile_id. This is in the event that you want to compile different versions of the same template, such as having separate templates compiled for different languages. You can also set the $compile_id variable once instead of passing this to each call to this function.

Example 14.19. display()

$smarty = new Smarty();

// 仅在缓存不存在的时候调用
if(!$smarty->isCached('index.tpl')) {

  // 数据
  $address = '245 N 50th';
  $db_data = array(
               'City' => 'Lincoln',
               'State' => 'Nebraska',
               'Zip' => '68502'

  $smarty->assign('Name', 'Fred');
  $smarty->assign('Address', $address);
  $smarty->assign('data', $db_data);


// 显示


Example 14.20. 其他 display() 的示例

模板资源的方式来显示不在 $template_dir目录下的模板。

// 绝对路径

// 绝对路径(使用file://)

// windows环境的绝对路径(务必是file:开头)

// 来自模板资源库db


参见 fetch()templateExists().

No comments for this page.