Home > Article > CMS Tutorial > How to use the DEDECMS extension tag
How to use the DEDECMS extension tag?
DDEECMS extension tag demonstration example
Recommended learning: DEMENCMS
We can look at a sample tag: demotag.lib .php,
if(!defined('DEDEINC')) { exit("Request Error!"); } function lib_demotag(&$ctag,&$refObj) { global $dsql,$envs; $attlist="row|12,titlelen|24"; FillAttsDefault($ctag->CAttribute->Items,$attlist); extract($ctag->CAttribute->Items, EXTR_SKIP); $revalue = ''; //------------------------------------------------------ $revalue = 'Hello Word!'; //------------------------------------------------------ return $revalue; } ?>
We will find that the tag works and our content is output.
$revalue = 'Hello Word!'; $revalue .=" Row:".$row.";TitleLen:".$titlelen;
So we can see that this attribute has been created as a variable and assigned a value.
Next we can further modify this label.
function lib_writerarc(&$ctag,&$refObj)
Next we can write query statements and related functions for underlying template processing
$revalue = ''; $innertext = $ctag->GetInnerText(); $ctp = new DedeTagParse(); $ctp->SetNameSpace('field', '[', ']'); $sql = "SELECT * FROM dede_archives WHERE writer='{$refObj->Fields['writer']}' limit 0, $row"; $dsql->Execute('me',$sql); while($rs = $dsql->GetArray('me')) { $rs['title'] = cn_substr($rs['title'], $titlelen); $ctp->LoadSource($innertext); foreach($ctp->CTags as $tagid=>$ctag) { if(!emptyempty($rs[strtolower($ctag->GetName())])) { $ctp->Assign($tagid,$rs[$ctag->GetName()]); } } $revalue .= $ctp->GetResult(); }
Finally return this value return $revalue;
The entire file content is as follows:
if(!defined('DEDEINC')) { exit("Request Error!"); } function lib_writerarc(&$ctag,&$refObj) { global $dsql,$envs; $attlist="row|12,titlelen|24"; FillAttsDefault($ctag->CAttribute->Items,$attlist); extract($ctag->CAttribute->Items, EXTR_SKIP); $revalue = ''; $innertext = $ctag->GetInnerText(); $ctp = new DedeTagParse(); $ctp->SetNameSpace('field', '[', ']'); $sql = "SELECT * FROM dede_archives WHERE writer='{$refObj->Fields['writer']}' limit 0, $row"; $dsql->Execute('me',$sql); while($rs = $dsql->GetArray('me')) { $rs['title'] = cn_substr($rs['title'], $titlelen); $ctp->LoadSource($innertext); foreach($ctp->CTags as $tagid=>$ctag) { if(!emptyempty($rs[strtolower($ctag->GetName())])) { $ctp->Assign($tagid,$rs[$ctag->GetName()]); } } $revalue .= $ctp->GetResult(); } return $revalue; } ?>
View and debug through dynamic browsing of the page?aid=3
{dede:writerarc row='10' titlelen='6'} [field:title/] {/dede:writerarc}
The above is the detailed content of How to use the DEDECMS extension tag. For more information, please follow other related articles on the PHP Chinese website!