Welcome Guest, Not a member yet? Register   Sign In
Template fragment solution, how to include other templates in a template.
#2

[eluser]xwero[/eluser]
You can half the lines you wrote by removing the variables you create. The variables have no further use.
Code:
function index()
{
    // content.tpl holds header,body,footer
    $content = array(
        'header' => $this->load->view('header.tpl', '', true),
        'body' => $this->load->view('body.tpl', '', true),
        'footer' => $this->load->view('footer.tpl', '', true)
    );
    
    // contents now holds all parsed html in $contents
    $data = array(
        'contents' => $this->load->view('contents.tpl', $content, true)
    );
    // output all contents
    $this->load->view('index',$data);
}
You could see nested views as templates but mentioning smarty and using the .tpl extension puts another spin on your post. Either this is a tutorial how to nest views or this is a tutorial about nesting templates using a template engine. Mentioning a template engine is distracting which could throw readers off.


Messages In This Thread
Template fragment solution, how to include other templates in a template. - by El Forum - 06-26-2009, 03:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB