开发者

Best way to include view within view in Codeigniter template using Dwoo?

开发者 https://www.devze.com 2023-01-06 15:09 出处:网络
I am using Codeigniter 1.7.2 and Phil Sturgeon\'s wonderful Dwoo wrapper which allows me to use the Dwoo template library in Codei开发者_Go百科gniter - http://philsturgeon.co.uk/code/codeigniter-dwoo

I am using Codeigniter 1.7.2 and Phil Sturgeon's wonderful Dwoo wrapper which allows me to use the Dwoo template library in Codei开发者_Go百科gniter - http://philsturgeon.co.uk/code/codeigniter-dwoo

I have a small question regarding the inclusion of other view template files within my template files. Say for example I have a dashboard.php file and I want to include a header and footer, what is the best way of doing that?

I usually would just do this:

<?php
$this->load->view('header');
?>

And this seems to work, but the whole point of using a template library is to separate code from my html. Can I use Dwoo's include functionality and if so, how?

Update

Since posting this I've worked out the ins and outs of Dwoo, you can include view files and use things like template inheritance to accomplish the same thing which is neater than assigning views to variables. I don't recommend the later unless you really need too.


I don't know about Dwoo, but you should be able to assign the parser's output to a variable and pass that to your view:

$data_array['header'] = $this->parser->parse('header', $header_data, TRUE);

If you don't need to parse your header/footer, just assign the view output to a variable and pass that to your template. The syntax is basically the same:

$data_array['header'] = $this->load->view('header', '', TRUE);

Ref: http://codeigniter.com/user_guide/libraries/parser.html and http://codeigniter.com/user_guide/general/views.html

Then, from the looks of it (reading Dwoo's wiki on usage), you'll just add {$header} to your template where you want your header to appear.

0

精彩评论

暂无评论...
验证码 换一张
取 消