Welcome Guest, Not a member yet? Register   Sign In
Master Page like Loading in a nice Core Extension.
#1

[eluser]SpYk3[/eluser]
Had a recent project where it would have been beneficial to write the site in ASP. Simply for the "Master Page" ability. Instead, I came up with a simple solution.

First I designed my header and footer php files. In the header file I include the HTML HEAD and everything beginning the page down to where I wanted content to load (for me, just pass one div inside BODY, the one div being a nav menu).

Then of course I created a footer file having the closing tags (</div>&lt;/body&gt;&lt;/html>) and any other footer elements I needed. In my case I needed a constant footer on each page showing social links, so it was included in this file.

Finally, the real work. Once you have your header and footer files, you have everything you need to move forward. I should note, I placed mine in `views/master` directory, so if you place yours elsewhere, you'll need to adjust the code.

The following code should be placed in a file named `MY_Loader.php` inside the `application/core` directory.

Code:
&lt;?php
/**
* /application/core/MY_Loader.php
*
*/
class MY_Loader extends CI_Loader {
public function master($view_name, $vars = array(), $return = FALSE) {
  $content  = $this->view('master/header', $vars, $return);
  $content .= $this->view($view_name, $vars, $return);
  $content .= $this->view('master/footer', $vars, $return);
  if ($return) return $content;
}
}

Use just like load->view

$this->load->master("viewName", $data);




Theme © iAndrew 2016 - Forum software by © MyBB