title: CodeIgniter/PHP - Calling a view from within a view
body: <p>Basically for my webapp I'm trying to organise it a bit better. As it at the moment, every time I want to load a page, I have to do it from my controller like so:</p>
  
  <pre><code>        $this-&gt;load-&gt;view('subviews/template/headerview');
      $this-&gt;load-&gt;view('subviews/template/menuview');
      $this-&gt;load-&gt;view('The-View-I-Want-To-Load');
      $this-&gt;load-&gt;view('subviews/template/sidebar');
      $this-&gt;load-&gt;view('subviews/template/footerview'); 
  </code></pre>
  
  <p>As you can tell it's not really very efficient.</p>
  
  <p>So I thought I'd create one 'master' view - It's called template.php. This is the contents of the template view:</p>
  
  <pre><code>&lt;?php
      $view = $data['view'];
  
          $this-&gt;load-&gt;view('subviews/template/headerview');
          $this-&gt;load-&gt;view('subviews/template/menuview');
          $this-&gt;load-&gt;view($view);
          $this-&gt;load-&gt;view('subviews/template/sidebar');
          $this-&gt;load-&gt;view('subviews/template/footerview');
  ?&gt;
  </code></pre>
  
  <p>And then I thought I'd be able to call it from a controller like this:</p>
  
  <pre><code>    $data['view'] = 'homecontent';
      $this-&gt;load-&gt;view('template',$data);
  </code></pre>
  
  <p>Unfortunately I simply cannot make this work. Does anyone have any ways around this or fixes I can put into place? I've tried putting ""s and ''s around $view in template.php but that makes no difference. The usual error is "Undefined variable: data" or "Cannot load view: $view.php" etc.</p>
  
  <p>Thanks folks!</p>
  
  <p>Jack</p>