CodeIgniter Forums
View files or template - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: View files or template (/showthread.php?tid=25952)

View files or template - El Forum - 01-01-2010

Hi guys,

Ive just started using CI and have so far been using view files, and just loading a different view file for each of the pages i have, e.g.
$page_body = "/home_page" and then this is loaded through the main page_structure.php file (which contains the code which echo's $page_body for example.

Im wondering what the advantages of using a template system/parser is? It kind of seems like (from what i have briefly read) that it just adds another step. As I have a main view file which then echos the sub regions it seems like this is all a template parser does, with a main template which contains regions.

Could someone explain the principal of it and why its better, and whether i should be using it, and any literature?

Many thanks! Smile

View files or template - El Forum - 01-01-2010

The basic idea is that you have to separate logic from presentation. Thats where the view in MVC comes in.

You could stop there, and have a single view file and use lots of lines of PHP code to produce your output, but that gets more and more difficult to maintain.

The main goal of a template system or parser is to remove part of the complexity, by having as few additions as possible to what should be a plain HTML file. So no PHP structures, no echo, but simple variable references. If you stick to CI views, you will still use PHP for control structures, and you have to be very careful not to make it a mess again.

We use Smarty as template engine, partly it allows use to do the above, but also because we have people working on the HTML side of things that either don't want to know PHP, or who do know PHP and could use their knowledge to alter business logic in views, or access data structures internal to the application, p.e. via the CI superobject.

View files or template - El Forum - 01-01-2010

[eluser]Colin Williams[/eluser]
I think you might be confusing two different things. A template system is just a way to structure your views. You don't really need any extra code to pull it off in CodeIgniter. Yes, I wrote a Template class that does this, but I find myself using it less and less.

A template parser is a type of pseudo code, like Smarty, Dwoo, et al. It's a way to keep view files free of PHP