DedeTag實(shí)例講解:如何構(gòu)建自己的標(biāo)簽
來源:程序員人生 發(fā)布時(shí)間:2014-02-26 07:20:21 閱讀次數(shù):3295次
DedeCMS如何構(gòu)建自己的標(biāo)簽?可以在根目錄創(chuàng)建個(gè)test.php,把下面的代碼放進(jìn)去,然后研究下這個(gè)文件的使用.詳細(xì)的教程其實(shí)在幫助中心已經(jīng)有了,這里只是用一個(gè)實(shí)例配合講解下(詳細(xì)參考>>>)
<?php
require_once (dirname(__FILE__) . "/include/common.inc.php");
require_once (DEDEINC . "/dedetag.class.php");
$dtp = new DedeTagParse();
//print_r($dtp);
//這里引入一個(gè)模板,或者你可以去處理一個(gè)字符串
//如果處理字符串使用$dtp->LoadSource(字符串);
$dtp->LoadTemplate(dirname(__FILE__)."/tpl.htm");
//print_r($dtp->CTags);
//遍歷讀取的標(biāo)簽,然后單個(gè)的進(jìn)行標(biāo)簽處理
foreach($dtp->CTags as $tid=>$ctag) {
//print_r($ctag);
//if($ctag->TagName=='go') echo "There is a tag name:go!";
if($ctag->TagName=='go') $dtp->Assign($tid, GoFunc($ctag->GetAtt("name"),$ctag->GetAtt("listtype"),$ctag->InnerText) );
}
//顯示解析后的頁面
$dtp->display();
//將解析后的頁面存儲(chǔ)到文件
$dtp->saveto(dirname(__FILE__)."/make.html");
//這個(gè)是標(biāo)簽處理函數(shù),用于返回替換值
function GoFunc($name,$listtype,$innertext)
{
return "Name:".$name.",Listtype:".$listtype.",Innertext:".$innertext;
}