• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Layout Class

[eluser]John Nickell[/eluser]
Greetings all,

I am still fairly new to CodeIgniter, but I love what I've been able to do with it so far.

Hopefully my first CodeIgniter library can help someone else, as well.

I know that CodeIgniter already has the ability to load view partials. Also, after looking at some of the templating engines out there, I decided that I wanted to stick with PHP. I was still hoping for some furthur structure/separation.

This library was inspired by:
1. The NetTuts+ tutorial about creating a Layout Manager:
2. ASP.NET Master Pages
3. My previous experiences with templating solutions

The syntax I was looking for amounted to this:

class home extends CI_Controller {
    public function index()
        $this->layout->setTitle('My Site', 'Welcome');
        $this->layout->view('home', $this->data);

<?php print $this->layout->html('doctype'); ?>
<title><?php print $this->layout->html('title'); ?></title>
<?php print $this->layout->html('headlink'); ?>
<?php print $this->layout->section('header'); ?>
<?php print $this->layout->section('content'); ?>
<?php print $this->layout->section('footer'); ?>
<?php print $this->layout->html('footscript'); ?>

The final result is slightly different, but works very well for me so far.

If anyone here might get some use out of it, check it out here:

Please let me know if you would have done it differently.

Any feedback positive or negative is appreciated.


John Nickell

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.