Flexible themes and layouts in CodeIginter


I still love CodeIgniter, the simplicity and robust core keeps me coming back even if it has fallen out of favour with the web community recently (I'm not going to get into that right now) but there has always been a few libraries that I felt were missing, a decent Auth library for one, but also a nicer way of dealing with views, layouts and themes. I can of course understand the reasons for leaving them out as both are not an every day need but I always seem get to a road block in my projects where I suddenly have a need for them, especially the layout library.

What I really needed was a library that would allow me to create multiple themes, inject partial views into the templates and keep the essential content completely separate so it could be reused whatever theme was enabled. Its not unusual to need a different theme for administrators or even allow logged in users to change their theme within their settings. It was clear that CodeIgniters basic loading of views was not going to be able to achieve all these requirements.

So I took the plunge and created a new layout library that worked the way I wanted, allowing default config settings, overriding settings in controllers, other libraries and helpers. The library should also work very nicely with a HMVC setup as all the modules could set partials separately with the template building the complete view on load.

In the future I plan to add a few more features which I regularly have a need for, like Facebook open graph and Twitter cards to the library, if you have any more features feel free to fork the code or give me a shout on twitter and I will see if it can be added.

The library is available to download right now on Github, also check out the documentation over in the lab. By the way there are some other great alternatives out there like the Ocular template library or Phil Sturgeon's template library, as always check them all out and decide which one best meets your needs before diving in.