【问题标题】:Define New Template Group in CI Template Library在 CI 模板库中定义新模板组
【发布时间】:2017-04-30 21:32:34
【问题描述】:

我一直在尝试在 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

【问题讨论】:

    标签: codeigniter templates


    【解决方案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');
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 我不知道这在这种情况下如何应用?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-29
      • 2011-06-30
      • 2020-04-09
      • 2019-04-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多