Class File
Include/dedetag. class. php
This file is the main template class used by dedecms V5.3 and earlier versions. It is an analytical template class, not a compilation class (the difference is that the former performs content replacement by obtaining the tag location, the latter directly parses the PHP code and executes the code twice)
I. template syntax
The zhimeng template engine is a template parser that uses XML Namespaces. The biggest advantage of using the zhimeng parser to parse templates is that you can easily define tag attributes, like using HTML, the template code is very intuitive and flexible. The new zhimeng template engine can not only parse templates, but also analyze error tags in templates.
1. The Code style of the zhimeng template engine is as follows:
{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}
Tip:
If you use tags with underlying templates, you must strictly use the format {dede: Tag Name attribute = 'value'} {/dede: Tag name}. Otherwise, an error is reported.
2. The zhimeng template engine has multiple built-in system tags that can be directly used in any scenario.
(1) globalMark to obtain an external variable. In addition to the Database Password, any configuration parameters of the system can be called in the form:
{Dede: global name = 'variable name'} {/dede: global}
Or
{Dede: global name = 'variable name '/}
The variable name cannot contain the $ symbol. For example, the variable $ inclu_cmspath should be written as {dede: global name = 'cfg _ cmspath '/}.
(2) foreachUsed to output an array in the form:
{Dede: foreach array = 'array name'} [field: key/] [field: value/] {/dede: foreach}
(3) includeIntroduce a file in the following format:
{Dede: include file = 'file name 'ismake = 'whether it is a dede template (yes/no )'/}
The search paths for files are in the absolute path, include folder, CMS installation directory, and CMS main template directory.
3. The woven dream mark allows the function to process the obtained value in any tag, in the form:
{Dede: Tag Name attribute = 'value' function = 'youfunction ("parameter 1", "parameter 2", "@ me ")'/}
@ Me indicates 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. Weaver dream tags allow limited programming extensions.
Format:
{Dede: tagname runphp = 'yes '}
$ Aaa = @ me;
@ Me = "123456 ";
{/Dede: tagname}
@ Me indicates the value of the tag itself, so in-tag programming cannot be usedEchoAnd so on, only all return values can be passed to @ me.
In addition, because the program code occupies the content of the underlying template InnerText, you must use the default InnerText only for the markup that needs to be programmed.
Ii. Resolution Method
There are four classes in dedetag. class. php.
Class DedeAttribute attribute Structure
Class DedeAttributeParse attribute parser
Structure of class DedeTag labels
Class DedeTagParse label parser
When using a parsing template, follow these steps:
1. Initialization:
$ Dtp = new DedeTagParse ();
2. Load the template/template string:
$ Dtp-> LoadTemplate (template file (absolute path); // The cache is generated and the template does not need to be parsed for the second time.
Or
$ Dtp-> LoadSource (string );
3. assign values to tags
Foreach ($ dtp-> CTags as $ tid => $ ctag ){
// Determine the ctag name and attributes and assign different values. Generally, function processing is used.
If ($ ctag-> GetName = 'mytag') $ dtp-> Assign ($ tid, mytagvalue ($ ctag ));
}
In the above example, the tag named mytag is directly transferred to the mytagvalue function for processing. In mytagvalue, you can determine the attributes of $ ctag and return different content.
In V5.3, except for dedicated tags such as field and list. * the labels of the class parsing files starting with include/taglib are all source code, which is automatically mapped by the system.
4. display or save as HTML
$ Dtp-> display ();
Or
$ Dtp-> SaveTo (static file name );
Secondary developers do not need to know the specific Parsing Method of the dedecms template. However, they should be very clear about the structure of the CTag class to determine the different attributes of tags for processing.
Class DedeTag { Var $ IsReplace = FALSE; // mark whether it has been replaced for the parser Var $ TagName = ""; // Tag Name Var $ InnerText = ""; // text between tags Var $ StartPos = 0; // mark the start position Var $ EndPos = 0; // mark the end position Var $ CAttribute = ""; // tag attribute description, that is, class DedeAttribute Var $ TagValue = ""; // tag Value Var $ TagID = 0;// Obtain the Tag Name and Value Function GetName () { Return strtolower ($ this-> TagName ); } Function GetValue () { Return $ this-> TagValue; } // The following two member functions are only for compatibility with the old version. Function GetTagName () { Return strtolower ($ this-> TagName ); } Function GetTagValue () { Return $ this-> TagValue; } // Obtain the specified tag attribute Function IsAttribute ($ str) { Return $ this-> cattriattribute-> IsAttribute ($ str ); } Function GetAttribute ($ str) { Return $ this-> cattriatt-> GetAtt ($ str ); } Function GetAtt ($ str) { Return $ this-> cattriatt-> GetAtt ($ str ); } Function GetInnerText () { Return $ this-> InnerText; } } |