Welcome Guest, Not a member yet? Register   Sign In
Best Strategy for Dynamic Header and Footer sections?
#2

[eluser]Rey Philip Regis[/eluser]
Well....I think what you need is to create a master template and in that master template you specify the parts of your page including the header, content and the footer. Ill show you a sample on how to do it. This is what we call loading a view within a view.

Code:
Controller:

Sample.php
class Sample extends Controller
{
   function Sample()
   {
     parent::Controller();

     // need this to use base_url() in the template.php
     $this->load->helper('url');
   }

   function index()
   {
      $data['title'] = 'Sample Template';
      $data['header'] = 'header_page'; // name of the view
      $data['content'] = 'main_page'; // name of the view
      $data['footer'] = 'footer_page'; // name of the view

      $this->load->view('template', $data);
   }
}


template.php
<html>
<head>
  <title><?php echo $title; ?></title>

  <link type="text/css" rel="stylesheet" href="<?php echo base_url().'system/css/default.css'; ?>" />
</head>

<body>

   <div id="wrapper">
      <div id="header">
         &lt;?php // dynamic loading of header just specify the $header in the controller
          $this->load->view($header);
         ?&gt;
      </div>

      <div id="content">
         &lt;?php // dynamic loading of content just specify the $content in the controller
          $this->load->view($content);
         ?&gt;
      </div>

      <div id="footer">
         &lt;?php // dynamic loading of footer just specify the $footer in the controller
          $this->load->view($footer);
         ?&gt;
      </div>
   </div>

&lt;/body&gt;

&lt;/html&gt;


main_page.php
<h1>This is the dynamic content (main page) of the page.....</h1>

header.php
<h1>Welcome to the website</h1>

footer.php
<h1>Copyright 2008</h1>


Hope this helps!


Messages In This Thread
Best Strategy for Dynamic Header and Footer sections? - by El Forum - 12-02-2008, 11:41 AM
Best Strategy for Dynamic Header and Footer sections? - by El Forum - 12-02-2008, 12:05 PM
Best Strategy for Dynamic Header and Footer sections? - by El Forum - 12-02-2008, 02:14 PM
Best Strategy for Dynamic Header and Footer sections? - by El Forum - 12-02-2008, 04:35 PM
Best Strategy for Dynamic Header and Footer sections? - by El Forum - 12-02-2008, 04:46 PM
Best Strategy for Dynamic Header and Footer sections? - by El Forum - 12-02-2008, 05:30 PM
Best Strategy for Dynamic Header and Footer sections? - by El Forum - 12-02-2008, 05:37 PM
Best Strategy for Dynamic Header and Footer sections? - by El Forum - 12-02-2008, 06:40 PM
Best Strategy for Dynamic Header and Footer sections? - by El Forum - 12-02-2008, 06:50 PM
Best Strategy for Dynamic Header and Footer sections? - by El Forum - 12-02-2008, 06:52 PM
Best Strategy for Dynamic Header and Footer sections? - by El Forum - 12-02-2008, 07:25 PM
Best Strategy for Dynamic Header and Footer sections? - by El Forum - 12-02-2008, 07:25 PM
Best Strategy for Dynamic Header and Footer sections? - by El Forum - 12-02-2008, 08:03 PM
Best Strategy for Dynamic Header and Footer sections? - by El Forum - 12-02-2008, 08:07 PM
Best Strategy for Dynamic Header and Footer sections? - by El Forum - 01-03-2009, 10:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB