您的位置:首页 > 其它

教程讲解dedecms动态编译式模版引擎

2016-03-21 10:59 204 查看
教程教程讲解dedecms动态编译式模版引擎,请参照DedeCMS论坛天涯版主的二次开发视频,否则各别地方可能会报错。
视频传送门:http://help.dedecms.com/video/template/2011/0720/320.html
转载请注明:http://blog.sina.com.cn/u/1756719835
设定文件名为code.php,以下为里面内容
<?php
require_once(dirname(__FILE__)."/include/common.inc.php");
require_once(dirname(__FILE__)."/include/channelunit.func.php");
require_once(dirname(__FILE__)."/include/dedetag.class.php");
if($action ==
'tpl'){
require_once(dirname(__FILE__)."/include/dedetemplate.class.php");
//设定模版目录,下面可以直接填入文件名
$tpl
= new DedeTemplate(dirname(__FILE__));
//载入模版文件
$tpl
->LoadTemplate('code.tpl.htm');
//---------------华丽丽的分割线------------

$title="我的DedeCMS网站";
$tpl
->SetVar("title",$title);

$arr=array(
name
=> 'DedeCMS',
company => 'DesDev
INC'
);
$tpl ->SetVar("arr",$arr);

$obj
= new stdclass;
$obj ->name='tianya';
$obj
->email='tianya@163.com';

$obj ->now
=time();
$tpl ->SetVar("obj",$obj);

$isshow =
true;
$tpl
->SetVar("isshow",$isshow);

//显示页面
//$tpl
->Display();
//生成htm文件
$tpl
->SaveTo('code.htm');
exit();
}
?>

设定文件名code.tpl.htm,以下为其内容
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta
http-equiv="Content-Type" content="text/html; charset=gb2312"
/>
<title>{dede:var
name='title'/}</title>
</head>
<body>
{dede:var name='title'/}<br />
名字:{dede:var.arr.name/}<br />
公司:{dede:var.arr.company/}<br
/>
{dede:cfg.webname/}<br />
{dede:global.cfg_webname/}<br />
{dede:object.obj->name/}<br />
{dede:object.obj->email/}<br
/>
{dede:object.obj->now function="MyDate('Y-m',@me)"/}<br
/>
遍历数组:<br />
{dede:array.arr
comment='这里是注释的位置'}
{dede:key/} = {dede:value/}<br
/>
{/dede:array}
{dede:php}
echo "hello word";
{/dede:php}
<br
/>
{dede:if
var.isshow}
需要显示
{else}
不需要显示
{/dede:if}
<br
/>
{dede:tianya name='hello' rstype='string'/}
<br
/>
{dede:memberlist}
{dede:field.mid/}-{dede:field.uname/}<br
/>
{/dede:memberlist}
{dede:include
filename='footer.tpl.htm'/}
</body>
</html>

设定文件名footer.tpl.htm其内容为:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta
http-equiv="Content-Type" content="text/html; charset=gb2312"
/>
<title>{dede:var
name='title'/}</title>
</head>
<body>
<br
/>-----------------------------------------------------------<br />
CMS和网站运营 is Powered by WordPress. Keso theme by dupola
</body>

</html>,请参照DedeCMS论坛天涯版主的二次开发视频,否则各别地方可能会报错。

视频传送门:http://help.dedecms.com/video/template/2011/0720/320.html

转载请注明:http://blog.sina.com.cn/u/1756719835

设定文件名为code.php,以下为里面内容

<?php
require_once(dirname(__FILE__)."/include/common.inc.php");
require_once(dirname(__FILE__)."/include/channelunit.func.php");
require_once(dirname(__FILE__)."/include/dedetag.class.php");

if($action ==
'tpl'){
require_once(dirname(__FILE__)."/include/dedetemplate.class.php");
//设定模版目录,下面可以直接填入文件名
$tpl
= new DedeTemplate(dirname(__FILE__));
//载入模版文件
$tpl
->LoadTemplate('code.tpl.htm');
//---------------华丽丽的分割线------------

$title="我的DedeCMS网站";
$tpl
->SetVar("title",$title);

$arr=array(
name
=> 'DedeCMS',
company => 'DesDev
INC'
);
$tpl ->SetVar("arr",$arr);

$obj
= new stdclass;
$obj ->name='tianya';
$obj
->email='tianya@163.com';

$obj ->now
=time();
$tpl ->SetVar("obj",$obj);

$isshow =
true;
$tpl
->SetVar("isshow",$isshow);

//显示页面
//$tpl
->Display();
//生成htm文件
$tpl
->SaveTo('code.htm');
exit();
}

?>

设定文件名code.tpl.htm,以下为其内容

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta
http-equiv="Content-Type" content="text/html; charset=gb2312"
/>
<title>{dede:var
name='title'/}</title>
</head>

<body>
{dede:var name='title'/}<br />

名字:{dede:var.arr.name/}<br />
公司:{dede:var.arr.company/}<br
/>

{dede:cfg.webname/}<br />
{dede:global.cfg_webname/}<br />

{dede:object.obj->name/}<br />
{dede:object.obj->email/}<br
/>

{dede:object.obj->now function="MyDate('Y-m',@me)"/}<br
/>
遍历数组:<br />
{dede:array.arr
comment='这里是注释的位置'}
{dede:key/} = {dede:value/}<br
/>
{/dede:array}

{dede:php}
echo "hello word";
{/dede:php}
<br
/>
{dede:if
var.isshow}
需要显示
{else}
不需要显示
{/dede:if}
<br
/>
{dede:tianya name='hello' rstype='string'/}
<br
/>
{dede:memberlist}
{dede:field.mid/}-{dede:field.uname/}<br
/>
{/dede:memberlist}

{dede:include
filename='footer.tpl.htm'/}
</body>
</html>

设定文件名footer.tpl.htm其内容为:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta
http-equiv="Content-Type" content="text/html; charset=gb2312"
/>
<title>{dede:var
name='title'/}</title>
</head>

<body>
<br
/>-----------------------------------------------------------<br />

CMS和网站运营 is Powered by WordPress. Keso theme by dupola

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: