模板 SmartTemplate高级使用

模板 SmartTemplate
访问网址:http://smarttemplate.yi.org/www.smartphp.net/
现在下载:http://smarttemplate.yi.org/download

 命名空间

<?php

    $admin  =  array(
                   'NAME'  =>; 'John Doe',
                   'AGE'   =>; '42',
               );
    $guest  =  array(
                   'NAME'  =>; 'Roger Rabbit',
                   'AGE'   =>; '16',
               );

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

    $template->;assign( 'admin', $admin );
    $template->;assign( 'guest', $guest );

    $template->;output();

?>;


模板(user.html): 占位符(PLACEHOLDER)对应数组,“.”对应数组“[]”

Admin Name: {admin.NAME}
Admin Age:  {admin.AGE}

Guest Name: {guest.NAME}
Guest Age:  {guest.AGE}

输出: 

Admin Name: John Doe
Admin Age:  42

Guest Name: Roger Rabbit
Guest Age:  16
 
 使用数组于多个命名空间

<?php

    $title  =  'Sample Links';  //  Page Title

    $target =  '_blank';        //  The Same Target for all links

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

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

    $template->;assign( 'TITLE', $title );
    $template->;assign( 'TARGET', $target );
    $template->;assign( 'links',  $links  );

    $template->;output();

?>;
注意:
TITLE 与 links..TITLE 使用不同的命名空间!
TARGET 不是 links 数组的成员. 如果使用在 BEGIN..END 块之内, 他必须被引用为 {parent.TARGET} 或者 {top.TARGET}.
其他可能的用法: 
{top.TITLE}, {parent.parent.PAGE_ID}, {top.users.ADMIN}, 等等..
模板(links.html): 

<html>;
<h3>; {TITLE} </h3>;

<!-- BEGIN links -->;

    <a target='{parent.TARGET}' href="{URL}">; {TITLE} </a>;

<!-- END links -->;

</html>;

输出: 

<html>;
<h3>; Sample Links </h3>;

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

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

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

</html>;

上一篇: smarttemplate模板嵌套方法   下一篇: 经过两周的忙碌,博客系统终于有形了

提交疑问

回顶部