導讀:故障問題故障問題DedeCms V5.3 常用函數參考:動態模板類 核心類文件 include/dedetemplate.class.php 用途:用于非核心模塊的動態頁面或列seo網站排名優化軟件網站推廣優化seo。
DedeCms V5.3 常用函數參考:動態模板類 核心類文件 include/dedetemplate.class.php 用途:用于非核心模塊的動態頁面或列表頁的模板解析,如:member/content_list.php ,通常是在 datalistcp.class.php 中使用,這個類在動態運行的情況下,由于本身是把模板編譯成PHP的,因此性能上會優級于舊的解析類,這個方法將在未來版本中作為通用的方式。 一、使用方法: $tpl = new DedeTemplate( 模板對象實例名稱,通常是t […]
DedeCms V5.3 常用函數參考:動態模板類
核心類文件
include/dedetemplate.class.php
用途:用于非核心模塊的動態頁面或列表頁的模板解析,如:member/content_list.php ,通常是在 datalistcp.class.php 中使用,這個類在動態運行的情況下,由于本身是把模板編譯成PHP的,因此性能上會優級于舊的解析類,這個方法將在未來版本中作為通用的方式。
一、使用方法:
$tpl = new DedeTemplate(
模板對象實例名稱,通常是'tpl',
[模板存放目錄(生成緩存時會存放在這個目錄),
include語法默認引用目錄]
);
通常情況下參數二和參數三是不必要的,如:
$tpl = new DedeTemplate('tpl');
如果在類文件中調用,應該加上設置:
$this->tpl->SetObject($this);
在一些塊調用中默認將使用當前類的成員函數。
$tpl->LoadTemplate(模板的物理路徑);
如果模板中帶有 {dede:config name='' value='網站seo優化培訓39;/}
可以在載入模板后,通過 $tpl->GetConfig($name) 獲得這些變量的值。
顯示頁面或保存頁面為文件
$tpl->Display();
$tpl->SaveTo(物理絕對路徑的文件名);
二、模板標記語法
1、標記通用特性
(1) 短標記
{dede:tagname.name/}
等同于
{dede:tagname name='' /}
(2) 塊標記
{dede:tagname}
循環代碼
{/dede:tagname}
2、標記的具體語法及對應的PHP代碼
(1) 配置變量
{dede:config name='' value=''/}
配置變量可以在載入模板后通過 $tpl->GetConfig($name) 獲得,僅作為配置,不在模板中顯示。
(2) 短標記
{dede:global.name/} 外部變量 等同于 <?php echo $name; ?>
{dede:var.name/} var數組 等同于 <?php echo $_vars['name']; ?>
{dede:field.name/} field數組 等同于 <?php echo $fields['name']; ?>
{dede:cfg.name/} 系統配置變量 等同于 <?php echo $cfg_name; ?>
考慮到大多數情況下都會在函數或類中調用模板,因此 $_vars、$fields 數組必須聲明為 global 數組,否則模板引擎無法獲得它的值從而導致產生錯誤。
(3) 自由調用塊標記
{tag:blockname bind='GetArcList' bindtype='class'}
循環代碼
{/tag:blockname}
必要屬性:
bind 數據源來源函數
bindtype 函數類型,默認是 class 可選為 sub
rstype 返回結果類型,默認是 array ,可選項為 string
自定義函數格式必須為 function(array $atts,object $refObj, array $fields);
在沒有指定 bind 綁定的函數的情況下,默認指向 MakePublicTag($atts,$tpl->refObj,$fields) 統一管理,這個函數存放在 cls_dede_tplinc.php 。
(4) 固定塊標記
[1] datalist
從綁定類成員函數GetArcList中獲取數組并輸出
{dede:datalist}
循環代碼
{/dede:datalist}
遍歷一個二給維數組,數據源是固定的,只適用用類調用。
等同于
{tag:blockname bind='GetArcList' bindtype='class' rstype='arrayu'}
循環代碼
{/tag:blockname}
[2] label
從綁定函數中獲取字符串值并輸出
等同于 {tag:blockname bind='func' bindtype='sub' rstype='string'/}
[3] pagelist
營銷型網站建設
從綁定類成員函數GetPageList中獲取字符串值并輸出
等同于 {tag:blockname bind='GetPageList' bindtype='class' rstype='string'/}
(5) include 語法
{dede:include file=''/}
{dede:include filename=''/}
(6) php 代碼塊
{dede:php
php 代碼
/}
或
{dede:php}
php代碼
{/dede:php}
(7) if 條件
僅支持 if ,else ,else 直接用{else}表示,但不支持{else if}這樣的語法 ,一般建議模板中不要使用太復雜的條件語法,如果確實有需要,可以直接使用 php 語法。
{dede:if 條件} a-block {else} b-block {/dede:if}
條件中允許使用 var.name 、 global.name 、 field.name、cfg.name 表示相應的變量。
如:
{dede:if field.id>10 }
{/dede:if}
(8) 遍歷一個 array 數組
{dede:array.name}
{dede:key/} = {dede:value/}
{/dede:array}
各種語法的具體編譯后的代碼,可查看 dede-template-class.php 的 function CompilerOneTag(&$cTag)。
塊調用示例代碼:
1、示例一
關鍵詞標簽: 模板 函數
聲明: 本文由我的SEOUC技術文章主頁發布于:2023-05-26 ,文章DedeCms 常用函數參考:動態模板類故障問題主要講述函數,模板,DedeCms 常用函數參考:動態模板類故障網站建設源碼以及服務器配置搭建相關技術文章。轉載請保留鏈接: http://www.bifwcx.com/article/web_8927.html