DEDECMS Two-time development: dedetag.class.php Static template class

Source: Internet
Author: User

DEDECMS Two-time development directory point this:dedecms two-time development Tutorials Directory

class file

include/dedetag.class.php

This file is the main template class used by Dedecms V5.3 and previous versions, it is the analytic template class, not the compiler (the difference is the former by obtaining the label location to replace the content, the latter is the direct parsing PHP code, two executions)

First, template syntax

Weaving dream template engine is a template parser using XML namespace form, the biggest advantage of using the Dream Parser parsing template is that it can easily make the attributes of the tag, it feels like HTML, so that the template code is very intuitive and flexible, The new version of the Weaving Dream template engine not only enables the parsing of templates but also analyzes the errors in the template.

1, Weaving Dream template Engine Code style has 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 the underlying template, you must strictly use {dede: Tag name attribute = ' value '}{/dede: Tag name} in this format, otherwise you will get an error.

2, weaving Dream template engine built-in multiple system tags, these system markings can be used in any situation directly.

(1) Global tag, which means to get an external variable, in addition to the database password, can invoke any configuration parameters of the system, in the form of:

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

Or

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

Where variable names cannot be added to the $ symbol, such as variables $cfg _cmspath, should be written as {Dede:global name= ' Cfg_cmspath '/}.

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

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

(3) include introduces a file in the form of:

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

The search path to the file is in order: Absolute path, include folder, CMS installation directory, CMS master template directory

3. The dream tag allows a function to be used in any tag to process the resulting value, in the form:

{dede: Tag name attribute = ' value ' function= ' youfunction ("parameter One", "parameter Two", "@me") '/}

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

{Dede:field name= ' pubdate ' function= ' strftime ("%y-%m-%d%h:%m:%s", "@me") '/}

4. Dream Weaving tags allow limited programming extensions.

The format is:

{dede:tagname runphp= ' yes '}

$AAA = @me;

@me = "123456";

{/dede:tagname}

@me represents the value of the tag itself, so in-markup programming is not possible with statements such as ECHO, only passing all return values to @me.

In addition, because the program code occupies the content of the underlying template innertext, the markup that needs to be programmed can only use the default innertext.

Second, the Analytic way

There are four of classes in dedetag.class.php.

Class Dedeattribute attribute structure representation

Class Dedeattributeparse Property Parser

Class DEDETAG Label Structure statement

Class Dedetagparse Tag Parser

The following steps are typically used when parsing a template with a parse class

1. Initialize:

$DTP = new Dedetagparse ();

2. Load template/Template string:

$DTP->loadtemplate (template file (absolute path)); The cache is generated, and the second does not need to parse the template

Or

$DTP->loadsource (string);

3. Assigning Values to tags

foreach ($DTP->ctags as $tid + $ctag) {   //To determine the name and attributes of Ctag, and to assign different values, usually using a function to handle   if ($ctag->getname== ' MyTag ') $DTP->assign ($tid, Mytagvalue ($ctag));   }

In the above example, the label called MyTag directly to the Mytagvalue function processing, mytagvalue to determine the various properties of $ctag, return different content.

In the V5.3 version, usually in addition to field, list and other special tags, where arc.* begins the class parsing files, tags are to should include/taglib source code, which is automatically mapped by the system.

4. Display or Save as HTML

$DTP->display ();

Or

$DTP->saveto (static file name);

For two developers, it is not necessary to know the Dedecms template specific parsing method, but it should be very clear CTAG the structure of this class, so as to determine the different attributes of the label processing.

Class Dedetag {var $IsReplace =false;//Whether the token has been substituted for the parser using var $TagName = "";//Tag name var $InnerText = "";//Label Note the text between the var $StartPos = 0; Mark start position var $EndPos = 0; Mark End position var $CAttribute = ""; Tag attribute description, which is the class dedeattribute var $TagValue = "";         The value of the tag var $TagID = 0;       Gets the name and value of the token function GetName () {return strtolower ($this->tagname);       } function GetValue () {return $this->tagvalue;       }//The following two member functions are only for compatibility with legacy function Gettagname () {return strtolower ($this->tagname);       } function Gettagvalue () {return $this->tagvalue; }//Gets the specified property of the token 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;   }   }

Dedecms two times development: dedetag.class.php Static template class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.