Get Smarty

Donate

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 Cheapglasses123.com and save up to 80%.

Where to buy prescription glasses? EyewearCanada.com is your best choice!

Visit www.sport-kick.com for cheap soccer cleats, sneakers and Soccer Jerseys updates

Advertisement

Name

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()


<?php
include(SMARTY_DIR.'Smarty.class.php');
$smarty = new Smarty();
$smarty->setCaching(true);

// 仅在缓存不存在的时候调用
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);

}

// 显示
$smarty->display('index.tpl');
?>

   

Example 14.20. 其他 display() 的示例

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


<?php
// 绝对路径
$smarty->display('/usr/local/include/templates/header.tpl');

// 绝对路径(使用file://)
$smarty->display('file:/usr/local/include/templates/header.tpl');

// windows环境的绝对路径(务必是file:开头)
$smarty->display('file:C:/www/pub/templates/header.tpl');

// 来自模板资源库db
$smarty->display('db:header.tpl');
?>

   

参见 fetch()templateExists().

Comments
No comments for this page.

Advertisement