首页 > 编程语言 >zblogphp如何使用模板引擎Template类如何使用

zblogphp如何使用模板引擎Template类如何使用

时间:2022-11-19 21:11:47浏览次数:45  
标签:调用 template zblogphp 编译 theme Template 根目录 模板

Template类的构造函数没有任何参数,所有的功能都是通过调用其成员函数实现的。

$template = new Template();
// 设置模板标签.zblog内置的模板变量和sidebar都在该函数绑定
$template->MakeTemplateTags();
// 设置主题(主题id,也是主题的目录名)
$template->theme = 'theme_id';

/*
* 设置模板名称
* 如 'index' 将渲染设定主题的根目录下的 `template/index.php` 模板文件
* 如 'list/category' 将渲染theme_id主题的根目录下的 `template/list/category.php` 模板文件
*/ 
if ($template->hasTemplate($templateName)) {
    $template->SetTemplate($templateName);
} else {
    $template->SetTemplate('index');
}

// 还可以指定主题下模板文件的存放路径(默认template)
// 将渲染设定主题的根目录下的 `custom_dir/` 子目录下的文件
$template->template_dirname = 'custom_dir';

/*
* 设置编译输出目录
* 该成员必须调用,且应该在为`$template->theme`赋值后再调用
* 如果不传参或参数为空,将设置编译目录为相对服务器根目录的:
* 'zblog/zb_users/cache/compiled/{$theme}/'
* 如果自定义了成员template_dirname(不为空或'template'),目录为:
* 'zblog/zb_users/cache/compiled/$theme__$template_dirname/'
* 实在是没有理由改动它
*/
$template->SetPath();

// 还可以结合pagebar使用
$pagebar = new Pagebar($route);
$template->SetTags('pagebar', $pagebar);

// 最后输出即可
$template->Display();

除了基本的使用,还有模板的判断、获取、编译等函数

// 返回当前要调用的已经编译好的模板文件的路径
function GetTemplate($name) {}
// 设置当前要调用的已经编译好的模板文件的名称(不存在直接报错)
function SetTemplate($templatename) {}
// 判断编译模板文件是否存在 ,若调用SetTemplate应该先调用它
function HasTemplate($name) {}

/*
* 编译模板有以下函数,无需关心内部逻辑
* 以上配置完成后,调用`BuildTemplate()`可以清空已编译的模板,并重新编译
* 
*/
BuildTemplate()
addNonexistentTags()
CompileFiles()
CompileFile($content)

标签:调用,template,zblogphp,编译,theme,Template,根目录,模板
From: https://www.cnblogs.com/chaihuibin/p/16907022.html

相关文章

  • 关于学生选课系统加模板这件事
    加模版啦!!!!index.jsp(主界面)<html><head><title>主界面</title></head><body><center><formaction="selectServlet"method="post"><table......
  • zblogphp的Pagebar类如何使用
    当我们为Zblog开发的插件/模板不走系统内置的ViewXX()编辑器时,模板中就没有pagebar对象了。想用系统的Pagebar功能,但是官方文档里没有介绍该怎么使用,就只能查看源码了。......
  • template
    templaterefs©xgqfrms2012-2021www.cnblogs.com/xgqfrms发布文章使用:只允许注册用户才可以访问!原创文章,版权所有©️xgqfrms,禁止转载......
  • <三>使用类模板实现STL Vector
    使用类模板实现STLVector,点击查看代码#include<iostream>usingnamespacestd;template<typenameT>classMyVector{public://构造函数MyVector<T>(intsi......
  • 带参数的ASP.NET MVC编辑器模板/ UIHint
    ASP.NETMVCEditor-Templates/UIHintwithparameters过去,我通过应用以下数据注释来像这样一直使用Editor-Templates:1[UIHint("SomeTemplate")]ViewMode......
  • bootstrap后台静态模板-search
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"/><metahttp-equiv="X-UA-Compatible"content="IE=edge"/><metaname="viewport"c......
  • bootstrap静态后台模板-头部导航条-自定义颜色
    <!DOCTYPEhtml><htmllang="en"backgound=""><head><metacharset="UTF-8"/><metahttp-equiv="X-UA-Compatible"content="IE=edge"/><metaname......
  • bootstrap静态后台模板-侧边栏导航条
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"/><metahttp-equiv="X-UA-Compatible"content="IE=edge"/><metaname="viewport"c......
  • bootstrap静态后台模板-头部+侧边栏导航条
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="utf-8"/><metaname="viewport"content="width=device-width,initial-scale=1"/><title>A......
  • [算法模板随笔] 背包Part 1 01背包
    最近在oiwiki上学感觉蛮快乐的,比啃大部头书感觉效率来得快很多今天来聊一下最经典的01背包问题吧.01背包大概就是这样一个问题:有N件物品和一个容量是V的背包......