muban大师 发表于 2020-1-16 13:40:20

dedecms调用指定模板源码分析

在dedecms当中,所有的后台栏目,都是指定所建的htm代码,进而网站会输出内容。最模板这次二次开发网站,有幸找了写该函数。
               
                        如下:
               
                       
               
                        function GetTempletFile()
               
                           {
               
                             global $cfg_basedir,$cfg_templets_dir,$cfg_df_style;
               
                             $cid = $this->ChannelUnit->ChannelInfos['nid',;
               
                             if(!empty($this->Fields['templet',))
               
                             {
               
                                   $filetag = MfTemplet($this->Fields['templet',);
               
                                 //if( !preg_match("#\/#", $filetag) ) $filetag = $GLOBALS['cfg_df_style',.'/'.$filetag;
               
                             }
               
                             else
               
                             {
               
                                   $filetag = MfTemplet($this->TypeLink->TypeInfos["temparticle",);
               
                       
               
                             }
               
                             $tid = $this->Fields['typeid',;
               
                             $filetag = str_replace('{cid}', $cid,$filetag);
               
                             $filetag = str_replace('{tid}', $tid,$filetag);
               
                             $tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$filetag;
               
                             if($cid=='spec')
               
                             {
               
                                   if( !empty($this->Fields['templet',) )
               
                                   {
               
                                       $tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$filetag;
               
                                   }
               
                                   else
               
                                   {
               
                                       $tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/article_spec.htm";
               
                                   }
               
                             }
               
                             if(!file_exists($tmpfile))
               
                             {
               
                                   $tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/".($cid=='spec' ? 'article_spec.htm' : 'article_default.htm');
               
                             }
               
                             if (!preg_match("#.htm$#", $tmpfile)) return FALSE;
               
                             return $tmpfile;
               
                           }
               
                        关键部分是      $tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$filetag;
               
                       
               
                        意思 文章页调用不同模型下的指定模板。   $filetag = MfTemplet($this->TypeLink->TypeInfos["temparticle",); 以这个循环指定。
               
                       
               
                        那么如果做单独页,需要指定某个模板,直接修改$tmpfile 就可以了。
页: [1]
查看完整版本: dedecms调用指定模板源码分析