http://www.smarty.net/
http://smarty.php.net/manual/en/


1.配置

        define("ROOTPATH",dirname(__FILE__)."/../");
        require_once("smarty/Smarty.class.php");

        /**
         * Smarty Template Class Initializtion
         */
        if( @constant( "ENABLED_TPL" ) ) {
            $obj_smarty = new Smarty();
            $obj_smarty->compile_check = true; //Open Compile Check
            $obj_smarty->debugging = false;// false || DEBUG || DEBUG_TPL; //debug On-off
            $obj_smarty->template_dir = ROOT_PATH."html"; //Set Template Document Root
            $obj_smarty->compile_dir = ROOT_PATH."cache"; //Set Template Cache File Document Root
            $obj_smarty->left_delimiter = "<!!"; //Set Template Left Delimiter
            $obj_smarty->right_delimiter = "!!>"; //Set Template Right Delimiter
            /**
             * 0:Smarty默认值,表示不对模板进行缓存 
             * 1:表示Smarty将使用当前定义的cache_lifetime来决定是否结束cache
             * 2:表示Smarty将使用在cache被建立时使用cache_lifetime这个值
             * 习惯上使用true与false来表示是否进行缓存
             */
            $obj_smarty->caching = true;
            $obj_smarty->cache_lifetime = 60 * 60 * 24;//-1:缓存从不过期,0:每次执行缓存总是被重新建立 
        } 


2.循环,section,sectionelse

        <!!sectionelse!!> 用来表示传入的数组变量为空时对模板进行的处理。

        <!!section name=one loop=$arr_result start=5 step=2 max=3 show=$show_customer_info!!> 
           <!!$arr_result[one].name!!> 
           <!!$smarty.section.one.iteration!!> //display the current loop iteration
           <!!$smarty.section.one.index!!>     //display the current loop index, starting with zero 
           <!!$smarty.section.one.first!!>     //first is set to true if the current section iteration is the first one
           <!!$smarty.section.one.last!!>      //last is set to true if the current section iteration is the last one. 
           <!!$smarty.section.one.loop!!>      //display the last index number that this section looped
           <!!$smarty.section.one.show!!>      //show is a boolean value, true or false
           <!!$smarty.section.one.total!!>     //display the number of iterations that this section will loop      
           <!!$smarty.section.name.rownum+$offset!!>//display the current loop iteration, starting with one $offset为基值
        <!!/section!!>


        <!!section name=one loop=$arr_result!!>
            <input type="checkbox" name="<!!$name!!>[]" }
                    {$weather}
                {/if}

相关文章:

  • 2021-07-21
  • 2021-07-18
  • 2021-05-11
  • 2021-08-05
  • 2021-06-24
猜你喜欢
  • 2022-12-23
  • 2021-05-06
  • 2022-12-23
  • 2022-03-05
  • 2022-12-23
  • 2021-04-13
相关资源
相似解决方案