zoukankan      html  css  js  c++  java
  • 简易Smarty模板类

    一个简易Smarty模板类,只需要一个文件。在ecshop里面找到的,感谢ecshop。

    测试代码:

    require_once 'cls_template.php';
    
    $smarty = new cls_template;
    
    $smarty->cache_lifetime = 30;
    $smarty->template_dir = dirname(__FILE__) . '/cache/smarty/template/';
    $smarty->cache_dir = dirname(__FILE__) . '/cache/smarty/cache/';
    $smarty->compile_dir = dirname(__FILE__) . '/cache/smarty/compiled/';
    
    $smarty->direct_output = false;
    $smarty->force_compile = true;
    
    $array = array(1, 2, 3, 4, 5);
    $smarty->assign('array', array( 
        'egw_polls' => array(
            'fd' => array(
                'poll_id' => array('type' => 'auto','nullable' => false),
                'poll_title' => array('type' => 'varchar', 'precision' => '100', 'nullable' => false),
                'poll_timestamp' => array('type' => 'int', 'precision' => '8', 'nullable' => false),
                'poll_visible' => array('type' => 'int', 'precision' => '4', 'nullable' => false, 'default' => '0'),
                'poll_votable' => array('type' => 'int', 'precision' => '4', 'nullable' => false, 'default' => '0'),
            ),
            'pk' => array('poll_id'),
            'fk' => array(),
            'ix' => array(),
            'uc' => array()
        ),
        'egw_polls_answers' => array(
            'fd' => array(
                'answer_id' => array('type' => 'auto', 'nullable' => false),
                'poll_id' => array('type' => 'int', 'precision' => '4', 'nullable' => false),
                'answer_text' => array('type' => 'varchar', 'precision' => '100', 'nullable' => false),
                'answer_votes' => array('type' => 'int', 'precision' => '4', 'nullable' => false, 'default' => '0'),
            ),
            'pk' => array('answer_id'),
            'fk' => array(),
            'ix' => array('poll_id'),
            'uc' => array()
        )
    ));
    
    $smarty->assign('name', 'omnitrix');
    
    $smarty->assign('user', array('name' => 'admin', 'password' => '456', 'email' => 'admin@admin.com'));
    
    $smarty->display('t1.tpl');

    测试模板:

    <br/>Name: {$name}
    <br/>Admin: {$user.name}
    <br/>Password: {$user.password}
    <br/>Email: {$user.email|upper|escape:url}
    
    {foreach from=$array key=table_name item=table_info name=abc}
    <br/>{$table_name}: {$smarty.foreach.abc.first} : {$smarty.server.PHP_SELF}
    {foreachelse}
    <br/>Nothing.
    {/foreach} 

    类文件cls_template.php位于ecshop/includes,可以在ecshop下载源码后找到。

  • 相关阅读:
    Unicode详解
    VC++ 6.0 中如何使用 CRT 调试功能来检测内存泄漏
    关于MFC下检查和消除内存泄露的技巧
    ASCII 、GB2312、GBK、GB18030、unicode、UTF8字符集编码详解
    A note from UrlEscape Function
    Unicode和UTF8之间的转换详解
    Base64编码
    全面解读WM_NOTIFY
    关于URL编码
    URL的#号
  • 原文地址:https://www.cnblogs.com/eastson/p/2722130.html
Copyright © 2011-2022 走看看