DedeTag實例講解:如何構建自己的標簽
來源:程序員人生 發布時間:2014-02-26 07:20:21 閱讀次數:3305次
DedeCMS如何構建自己的標簽?可以在根目錄創建個test.php,把下面的代碼放進去,然后研究下這個文件的使用.詳細的教程其實在幫助中心已經有了,這里只是用一個實例配合講解下(詳細參考>>>)
<?php
require_once (dirname(__FILE__) . "/include/common.inc.php");
require_once (DEDEINC . "/dedetag.class.php");
$dtp = new DedeTagParse();
//print_r($dtp);
//這里引入一個模板,或者你可以去處理一個字符串
//如果處理字符串使用$dtp->LoadSource(字符串);
$dtp->LoadTemplate(dirname(__FILE__)."/tpl.htm");
//print_r($dtp->CTags);
//遍歷讀取的標簽,然后單個的進行標簽處理
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();
//將解析后的頁面存儲到文件
$dtp->saveto(dirname(__FILE__)."/make.html");
//這個是標簽處理函數,用于返回替換值
function GoFunc($name,$listtype,$innertext)
{
return "Name:".$name.",Listtype:".$listtype.",Innertext:".$innertext;
}