欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

dedecms 中 解析模板标签 ask的模板文件中可以这样解析 pasterTempletDiy 有大用

shiping1 的头像

在我们自定义的php          include 模板htm文件中

我们要在这个htm文件中包含htm文件

使用

<?php
 pasterTempletDiy("/shipingzhong/zxbm-headerjscss.htm");
 ?>

 

我们同时在 helper中定义 pasterTempletDiy函数

 //解析模板标签 一般情况下 用下面这个就可以了
function pasterTempletDiy($path)
{
    require_once(DEDEINC."/arc.partview.class.php");
    global $cfg_basedir,$cfg_templets_dir;
    $tmpfile = $cfg_basedir.$cfg_templets_dir."/".$path;//模版文件的路径
    $dtp = new PartView();
    $dtp->SetTemplet($tmpfile);
    $dtp->Display();
}

//自己亲自做的 可以看多个目录中是否有模板文件
 //解析模板标签
function pasterTempletDiy($filename)
{
    require_once(DEDEINC."/arc.partview.class.php");
    global $cfg_basedir,$cfg_templets_dir,$cfg_df_style;
     //服务器 本地不同
    $commonTemplatePath = '/home/wwwroot/common_aaaa_com/public_html/templets/';
    $commonTemplatePath1 = '/home/wwwroot/common_aaaa_com/public_html/templets/';
    //在其中判断是否存在文件
    if( file_exists($cfg_basedir.$cfg_templets_dir.'/'.$cfg_df_style.'/'.$filename)){
         $okfile = $cfg_basedir.$cfg_templets_dir.'/'.$cfg_df_style.'/'.$filename;
    }
    //下面是是共用的文件
    else if((file_exists($commonTemplatePath.$filename))){
        $okfile = $commonTemplatePath.$filename;
    }
    //下面是是共用的文件
    else if((file_exists($commonTemplatePath1.$filename))){
        $okfile = $commonTemplatePath.$filename;
    }
    $dtp = new PartView();
    $dtp->SetTemplet($okfile);
    $dtp->Display();
}


 

 //解析模板标签 一般情况下 用下面这个就可以了 有传个栏目$tid,根据$tid得到position
function pasterTempletDiy($path,$tid)
{
    require_once(DEDEINC."/arc.partview.class.php");
    global $cfg_basedir,$cfg_templets_dir;
    global $cfg_list_symbol;
    global $cfg_indexname;
    global $cfg_basehost;

    

    include(DEDEINC."/arc.listview.class.php");
    $lv = new ListView($tid);
    $tmpfile = $cfg_basedir.$cfg_templets_dir."/".$path;//模版文件的路径
    $dtp = new PartView();

    

    if(!empty($tid)){
    $dtp->Fields['position'] = $lv->Fields['position'];
//任何一个 用 {dede:field.字段名 /} 都可以在这里赋一下值
    }

    

    $dtp->SetTemplet($tmpfile);

    

    $dtp->Display();
}
普通分类: