6

I've been using django for some time and I decided to start a new project but this time in Codeigniter, I used to extend the template file in my views and put content inside the {% block content %} block but it seens to be different in CodeIgniter.

In CodeIgniter I have something like:

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

But is there a way to have an unique file with header, content and footer like this?

<html>
    <head><title>Test</title></head>
    <body>
        <div id="header">Welcome</div>
        <div id="content">
        </div>
        <div id="footer"> 2013 - Tectcom Telecom</div>
    </body>
</html>

And put a view file with a form inside the content div?

2 Answers2

9

Update your html (layout) file like this:

<div id="content"><?php $this->load->view($content) ?></div>

In your controller, call the view like this:

$view_data = array();
$view_data['content'] = 'form_add_customer';
$this->load->view('path/to/layout', $view_data);
minboost
  • 2,555
  • 1
  • 15
  • 15
0

I've used the "Most Simple Template Library for CodeIgniter" in the past with success for smaller projects. I believe it'll provide with the functionality that you require allowing you to have placeholders in a 'template' which you can update in your controller logic.

Malachi
  • 33,142
  • 18
  • 63
  • 96