Home > CMS Tutorial > DEDECMS > body text

How to use the DEDECMS extension tag

藏色散人
Release: 2020-01-15 10:49:25
Original
1780 people have browsed it

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; 
} 
?>
Copy after login

We will find that the tag works and our content is output.

How to use the DEDECMS extension tag

$revalue = 'Hello Word!'; 
$revalue .=" 
Row:".$row.";TitleLen:".$titlelen;
Copy after login

How to use the DEDECMS extension tag

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)
Copy after login

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(); 
}
Copy after login

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; 
} 
?>
Copy after login

View and debug through dynamic browsing of the page?aid=3

{dede:writerarc row='10' titlelen='6'} 
[field:title/]  
{/dede:writerarc}
Copy after login

How to use the DEDECMS extension tag

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!