在CI模板库中定义新模板组

时间:2011-03-16 02:10:41

标签: codeigniter templates

我一直在尝试在codeigniter模板库中定义一个新的模板组,但是我一直收到错误,说该组不存在/尚未定义。下面是定义默认模板组的代码,该模板组设置为活动状态。

$template['default']['template'] = 'templates/welcome';
$template['default']['regions'] = array(
   'header' => array('content' => array("<h1>Adrian's Branch</h1>")),
   'content',
   'footer' => array('content' => array('<p id="copyright">0bytes</p>'))
);
$template['default']['parser'] = 'parser';
$template['default']['parser_method'] = 'parse';
$template['default']['parse_template'] = FALSE;

我认为通过将“default”替换为我的自定义组名称来定义自定义组时,相同的方法是适用的吗?

在我的控制器中,我打电话给...

$this->template->set_template('custom_template_name');

但这不起作用?我这样做了吗?

可以在此处找到用户指南:http://williamsconcepts.com/ci/codeigniter/libraries/template/reference.html

2 个答案:

答案 0 :(得分:1)

所以我想出来了。这是我原来的,但没有工作,现在是。

//mobile template group
$template['mobile']['template'] = 'templates/mobile/welcome';
$template['mobile']['regions'] = array(
   'header' => array('content' => array("<h1>Adrian's Branch</h1>")),
   'content',
   'footer' => array('content' => array('<p id="copyright">0bytes Mobile</p>'))
);
$template['mobile']['parser'] = 'parser';
$template['mobile']['parser_method'] = 'parse';
$template['mobile']['parse_template'] = FALSE;

除了组名不同之外,上面的代码与默认代码完全相同。要激活此模板,我只需致电。

$this->template->set_template('mobile');

答案 1 :(得分:0)

您可能需要查看文件夹和路径文件的命名约定:)