发新话题
打印

SmartTemplate学习笔记 基本方法append()

SmartTemplate学习笔记 基本方法append()

SmartTemplate学习笔记 基本方法append()
转载注明:PHP开发资源网(http://www.phpres.com/) :小强

void append ( string PLACEHOLDER, mixed CONTENT )
追加内容给模板占位符. 可以使用散列数组或者标量.
例子1
复制内容到剪贴板
代码:
<?php

  $page = new SmartTemplate('links.html');

  $page->append('links' , array(
                      'TITLE' => 'PHP',
                      'URL'   => 'http://www.php.net/'
                  ));
  $page->append('links' , array(
                      'TITLE' => 'Apache',
                      'URL'   => 'http://www.apache.org/'
                  ));
  $page->append('links', array(
                      'TITLE' => 'MySQL',
                      'URL'   => 'http://www.mysql.com/'
                  ));
  $page->output();

?>
模板(links.html): 列表追加为行
复制内容到剪贴板
代码:
<html>
<h3> Sample Links </h3>

<!-- BEGIN links -->

  <a href="{URL}"> {TITLE} </a>

<!-- END links -->

</html>
输出:
引用:
<html>
<h3> Sample Links </h3>

  <a href="http://www.php.net/"> PHP </a>

  <a href="http://www.apache.org/"> Apache </a>

  <a href="http://www.mysql.com/"> MySQL </a>

</html>
例子2 (标量):
复制内容到剪贴板
代码:
<?php

  $page = new SmartTemplate('template.html');

  $page->append('TITLE' , 'Hello ');
  $page->append('TITLE' , 'World ');
  $page->append('TITLE' , '!');

  $page->output();

?>
模板(template.html): 标量为内容的追加
复制内容到剪贴板
代码:
<html> {TITLE} </html>
输出:
引用:
<html> Hello World ! </html>
phpres我爱你[/red]
向大家推荐极品模板引擎:smarttemplate

TOP

发新话题