DEDECMS Two-time development directory point this:dedecms two-time development Tutorials Directory
Core class files
include/dedetemplate.class.php
Purpose: Template parsing for dynamic pages or list pages for non-core modules, such as: member/content_list.php, usually used in datalistcp.class.php, which, in the case of dynamic operation, is compiled into PHP by itself. As a result, the performance will be superior to the old parsing class, which will be used as a generic approach in future releases.
First, how to use:
$TPL = new Dedetemplate (
Template object instance name, usually ' TPL ',
[The template stores the directory (which is stored in this directory when the cache is generated),
Include syntax default reference directory]
);
Typically, parameter two and parameter three are unnecessary, such as:
$TPL = new Dedetemplate (' TPL ');
If called in the class file, the setting should be added:
$this->tpl->setobject ($this);
The member functions of the current class are used by default in some block calls.
$tpl->loadtemplate (The physical path of the template);
If the template has {dede:config name= ' value= '/}
The values of these variables can be obtained by $TPL->getconfig ($name) after the template is loaded.
Show page or save page as file
$tpl->display ();
$tpl->saveto (the file name of the physical absolute path);
Second, template markup syntax
1, marking general characteristics
(1) Short mark
{dede:tagname.name/}
Equivalent to
{dede:tagname name= '/}
(2) block mark
{Dede:tagname}
Loop code
{/dede:tagname}
2, the specific syntax of the tag and the corresponding PHP code
(1) Configuration variables
{dede:config name= ' value= '/}
Configuration variables can be obtained by $TPL->getconfig ($name) After loading the template, only as a configuration and not displayed in the template.
(2) Short mark
{dede:global.name/} external variables are equivalent to
The {dede:var.name/} var array is equivalent to
The {dede:field.name/} field array is equivalent to
The {dede:cfg.name/} system configuration variable is equivalent to
Given that in most cases a template is called in a function or class, the $_vars, $fields array must be declared as a global array, or the template engine cannot get its value, resulting in an error.
(3) Free Call block tag
{tag:blockname bind= ' getarclist ' Bindtype= ' class '}
Loop code
{/tag:blockname}
Required attributes:
Bind data Source Source function
Bindtype function type, default is class optional sub
Rstype Returns the result type, which is an array by default and can be selected as String
The custom function format must be function (array $atts, Object $REFOBJ, array $fields);
In the absence of a function that specifies bind binding, the default point is to Makepublictag ($atts, $tpl->refobj, $fields) unified management, which is stored in cls_dede_tplinc.php.
(4) Fixed block marking
[1] DataList
Gets the array from the binding class member function getarclist and outputs
{Dede:datalist}
Loop code
{/dede:datalist}
Traversing a two-dimensional array, the data source is fixed and only applicable to class invocation.
Equivalent to
{tag:blockname bind= ' getarclist ' bindtype= ' class ' Rstype= ' Arrayu '}
Loop code
{/tag:blockname}
[2] Label
Gets the string value from the binding function and outputs
Equivalent to {tag:blockname bind= ' func ' bindtype= ' Sub ' rstype= ' String '/}
[3] PageList
Gets the string value from the Binding class member function getpagelist and outputs
Equivalent to {tag:blockname bind= ' getpagelist ' bindtype= ' class ' rstype= ' string '/}
(5) Include syntax
{dede:include file= '/}
{dede:include filename= '/}
(6) PHP code block
{dede:php
PHP code
/}
Or
{dede:php}
PHP code
{/dede:php}
(7) If condition
It is supported only if, else, else is represented directly with {else}, but does not support the syntax of {else if}, it is generally recommended that you do not use too complex conditional syntax in the template, and if you do, you can use PHP syntax directly.
{dede:if Condition} a-block {Else} b-block {/dede:if}
Conditions allow the use of Var.name, Global.name, Field.name, cfg.name to represent the corresponding variable.
Such as:
{Dede:if field.id>10}
{/dede:if}
(8) traversing an array of arrays
{Dede:array.name}
{dede:key/} = {dede:value/}
{/dede:array}
The specific compiled code for each syntax can be viewed in the dede-template-class.php function Compileronetag (& $cTag).
Block Invoke Sample code:
1. Example One
{tag:datalist timeformat= ""}<br/> <tr><br/> <td class= ' col1 ' ><br/> <div>?<a href= ' {tag:field.arcurl/} ' >{tag:field.title/}</a></div><br/> <!--div class= ' descriptions ' > {tag:field.description function= "Cnsubstr (@me, max)"/}...</ div--><br/> </td><br/> <td class= ' col2 ' >{tag:field.formattime/}</td ><br/> </tr><br/> {/tag:datalist}
Post-compilation Code
<?php $atts = Array (); $atts [' tagname '] = ' DataList '; $atts [' timeformat '] = '; $blockValue = $this->refobj->getarclist ($atts, $this->refobj, $fields); foreach ($blockValue as $key = $fields) { ?> <tr> <td class= ' col1 ' > <div >?<a href= ' <?php echo $fields [' Arcurl '];?> ' ><?php echo $fields [' title '];? ></a></div > <!--div class= ' descriptions ' > <?php echo cnsubstr ($fields [' description '],150];? >...</ div--> </td> <td class= ' col2 ' ><?php echo $fields [' formattime '];?></td> </tr> <?php } ?>
2. Example Two
{tag:article sort= ' new ' titlelen= ' ' row= '}<br /> <dd>[{tag:field.typename/}]<a Href= "{tag:field.arcurl/}" >{tag:field.title function= "Cnsubstr (@me)"/}</A></DD><BR/ > {/tag:article}
Post-compilation Code
<?php $atts = Array (); $atts [' tagname '] = ' article '; $atts [' sort '] = ' new '; $atts [' titlelen '] = ' + '; $atts [' row '] = ' ten '; $blockValue = Makepublictag ($atts, $this->refobj, $fields); if (Is_array ($blockValue) && count ($blockValue) > 0) { foreach ($blockValue as $key = $fields) { ?> <dd>[<?php echo $fields [' TypeName '];? >]<a href= "<?php echo $fields [' Arcurl '];? > "><?php echo cnsubstr ($fields [' title '],24);?></a></dd> <?php } } ?>
Dedecms two times development: dedetemplate.class.php Dynamic template class