Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter template libraries, with partial views - which one?

I started researching this topic for a couple of reasons...

1) To reduce repetitive code in my controllers 2) To configure 3 main layouts used in my website - 1 column, 2 column and 3 column pages 3) To be able to have separate partial view files, and load them accordingly according to the template (main-content, header, footer and sidebar)

I have googled this topic and come up with very few examples with user-friendly documentation, and I was hoping for some guidance.

http://net.tutsplus.com/tutorials/php/an-introduction-to-views-templating-in-codeigniter/ by Sam Stevens is great... but lacks the dynamicism needed to load individual view files for each template.

https://github.com/jenssegers/CodeIgniter-Template-Library by Jens Segers just confuses the life out of me with this unnecessary widget malarkey.

http://philsturgeon.co.uk/blog/2009/12/CodeIgniter-Template-library by Phil Sturgeon looks good... but lack of docs and bugs make it very difficult for a newbie like me to get up and running.

http://williamsconcepts.com/ci/codeigniter/libraries/template/index.html by William Concepts seems to be the best from what I can gauge from other users - but it's not out-of-the-box ready, and I am getting errors about trying to define the likes of header twice! It's just not working for me.

If someone can advise me which library (or other one) would best fulfill what I'm trying to achieve I could then put all my attention into implementing and understanding it, instead of jumping between examples...

Also, all of these examples seem to be (originally) YEARS old (bar Sam Steven's) which makes me wonder, is there not newer or more recent examples available?

like image 993
user2505513 Avatar asked Dec 08 '25 09:12

user2505513


1 Answers

A very similar question has been asked regarding which templating library is best. I would even consider flagging this as a duplicate question, but since you asked "is there not newer or more recent examples available?" -- I'll bite.

You should try and use Stencil. It was released this year, is very well documented, and I use it on all my CodeIgniter projects (full disclosure: I am the creator).

Some of it's features are:

  1. Easily set titles
  2. Simple Layouts
  3. Page-specific assets (js and css, perfect for jQuery plugins)
  4. Page-specific meta data
  5. Tons of HTML5 helpers
  6. Flexible ways of binding data to views
  7. Slices (also called partials, includes, nested views, elements, etc)
  8. Slice Callbacks (also called view models where you can execute a block of code every-time a Slice is used)

Again, this is something I built though. It's all about finding the right tools for the job, and you should research what works best for your project.

Links

GitHub | Docs | Demo

like image 190
envysea Avatar answered Dec 10 '25 01:12

envysea



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!