• 简易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下载源码后找到。

  • 相关阅读:
    Git+GitHub+SaltStack
    系统运维
    Linux之Ubuntu
    TCP/IP 必知必会的十个问题
    Github常见操作和常见错误!
    Git钩子:自定义你的工作流
    Spring 梳理
    Spring 梳理
    Spring 梳理
    Spring boot 官网学习笔记
  • 原文地址:https://www.cnblogs.com/eastson/p/2722130.html
Copyright © 2020-2023  润新知