Home  >  Article  >  CMS Tutorial  >  What is the DEDECMS static template class file?

What is the DEDECMS static template class file?

藏色散人
藏色散人Original
2019-12-28 09:17:021944browse

What is the DEDECMS static template class file?

What is the DEDECMS static template class file?

Static template class file Dreamweaver template engine is a template parser that uses XML namespace form

Recommended learning: Dreamweaver cms

The biggest advantage of using the Dreamweaver parser to parse templates is that you can easily specify the attributes of the tag. It feels like using HTML, making the template code very intuitive and flexible. The new version of the Dreamweaver template engine can not only realize the template Parsing can also analyze incorrect markup in templates.

include/dedetag.class.php This file is the main template class used by dedecms V5.3 and previous versions. It is an analytical template class, not a compiled one (the difference is that the former is performed by obtaining the tag position. Content replacement, the latter is directly parsed PHP code, executed twice)

1. Template syntax

1. The code styles of the Dreamweaver template engine have the following forms:

{dede:Tag name attribute='value'/}

{dede:Tag name attribute='value'}{/dede:Tag name}

{dede:Tag name Attribute = 'value'} Custom style template (InnerText) {/dede: tag name}

Tips:

If you use a tag with an underlying template, you must strictly use {dede: tag name Attribute='value'}{/dede:tag name} This format, otherwise an error will be reported.

2. The DreamWeaver template engine has multiple built-in system tags, and these system tags can be used directly in any situation.

(1) The global mark means to obtain an external variable. In addition to the database password, it can call any configuration parameters of the system. The form is:

{dede:global name='variable name '}{/dede:global}

or

{dede:global name='variable name'/}

The variable name cannot be added with the $ symbol, such as variable $ cfg_cmspath should be written as {dede:global name='cfg_cmspath'/}.

(2) foreach is used to output an array, in the form:

{dede:foreach array='array name'}[field:key/] [field:value/]{/ dede:foreach}

(3) include introduces a file in the form:

{dede:include file='file name' ismake='whether it is a dede plate template (yes/no) '/}

The search path for files is in the order: absolute path, include folder, CMS installation directory, CMS main template directory

3. The Dreamweaver tag is allowed to be used in any tag The function processes the obtained value in the form:

{dede: tag name attribute='value' function='youfunction("Parameter 1", "Parameter 2", "@me")' /}

Where @me is used to represent the value of the current tag, other parameters are determined by your function, for example:

{dede:field name='pubdate' function='strftime ("%Y-%m-%d %H:%M:%S","@me")'/}

4. The Dreamweaver mark allows limited programming expansion.

The format is:

The code is as follows:

{dede:tagname runphp='yes'} 
$aaa = @me; 
@me = "123456"; 
{/dede:tagname}

@me represents the value of the tag itself, so statements such as echo cannot be used in programming within the tag, only Pass all return values ​​to @me.

In addition, because the program code occupies the content of the underlying template InnerText, the tags that require programming can only use the default InnerText.

2. Parsing method

There are four classes in dedetag.class.php

class DedeAttribute attribute structure expression

class DedeAttributeParse attribute parser

class DedeTag tag structure expression

class DedeTagParse tag parser

When using the parsing class to parse templates, the following steps are generally followed

1. Initialization:

$dtp = new DedeTagParse();

2. Load template/template string:

$dtp->LoadTemplate(template file (absolute path)); / / will generate a cache, and there is no need to parse the template the second time

or

$dtp->LoadSource(string);

3. Assign a value to the tag

foreach($dtp->CTags as $tid=>$ctag) {

//Determine the name and attributes of ctag, and assign different values, usually using functions

if($ctag->GetName=='mytag') $dtp->Assign($tid, mytagvalue($ctag) );

}

In the above example , directly transfer the tag named mytag to the mytagvalue function for processing. Mytagvalue determines each attribute of $ctag and returns different contents.

In the V5.3 version, usually in addition to special tags such as field and list, the tags of files parsed by classes starting with arc.* correspond to the source code of the include/taglib. This is determined by the system. Automatic mapping is performed.

4. Display or save as HTML

$dtp->display();

or

$dtp->SaveTo(static file name);

对于二次开发人员而言,不大需要知道dedecms模板具体解析方式,不过应该十分清楚CTag这个类的结构,从而判断标签不同属性进行处理。 

代码如下:

class DedeTag 
{ 
var $IsReplace=FALSE; //标记是否已被替代,供解析器使用 
var $TagName=""; //标记名称 
var $InnerText=""; //标记之间的文本 
var $StartPos=0; //标记起始位置 
var $EndPos=0; //标记结束位置 
var $CAttribute=""; //标记属性描述,即是class DedeAttribute 
var $TagValue=""; //标记的值 
var $TagID = 0; 
//获取标记的名称和值 
function GetName() 
{ 
return strtolower($this->TagName); 
} 
function GetValue() 
{ 
return $this->TagValue; 
} 
//下面两个成员函数仅是为了兼容旧版 
function GetTagName() 
{ 
return strtolower($this->TagName); 
} 
function GetTagValue() 
{ 
return $this->TagValue; 
} 
//获取标记的指定属性 
function IsAttribute($str) 
{ 
return $this->CAttribute->IsAttribute($str); 
} 
function GetAttribute($str) 
{ 
return $this->CAttribute->GetAtt($str); 
} 
function GetAtt($str) 
{ 
return $this->CAttribute->GetAtt($str); 
} 
function GetInnerText() 
{ 
return $this->InnerText; 
} 
}

The above is the detailed content of What is the DEDECMS static template class file?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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