Codeigniter template libraries, with partial views - which one? Codeigniter template libraries, with partial views - which one? codeigniter codeigniter

Codeigniter template libraries, with partial views - which one?


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 ablock 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


This is more of an opinion based question rather than one someone can factually answer. There is not the best but just different tools for the job. First I will say that the reason why you may only be seeing years old libraries for CI is because many have jumped shipped to newer frameworks that use namespacing and newer php 5.3 features. This is not saying CI is bad, I still use it for a few of my projects.

Phil Sturgeon used to be a core contributor to CI but has now moved on to Laravel if I remember correctly. (Laravel is also what I have been migrating to as well)

Tutsplus is a great site filled with awesome information. In fact just recently they have a new premium course for CI: https://tutsplus.com/course/codeigniter-best-practices/

Beyond those I do not know of the other two and cannot give you any information. Me, I do not use any template libraries and just give each partial view a name/index in an object and if the name exists then I call the partial view and load it with the properties in the object with the same name (header, css, script, content, footer, etc). Then you just have a template view that acts as a .net master page and you just inject your partial views into it. You can also do this by creating a hook. Perhaps a google search for CI template hooks as well.


All the examples of this page are not maintained.For templating in CodeIgniter, you can use the CI Template Parser Class, but is very lean.

Otherwise, you can use Smarty or Twig, they have a very powerful feature for partial views: template inheritance.

Template inheritance is an approach to managing templates that resembles object-oriented programming techniques. Instead of the traditional use of {include ...} tags to manage parts of templates, you can inherit the contents of one template to another (like extending a class) and change blocks of content therein (like overriding methods of a class.) This keeps template management minimal and efficient, since each template only contains the differences from the template it extends. Template inheritance allows you to build a base "skeleton" template that contains all the common elements of your site and defines blocks that child templates can override.