CodeIgniter Template Parser Class
When we talk about template parser, we basically refer to a template engine, that let’s you seperate your logic with the design. So the real and most obvious benefit of using a template parser would be to have both designer and developer work at the same time during the same project. Now, many of you might say that, this benefit is already visible with the MVC approach that CodeIgniter already gives us, but let’s look a little deeper in, and see how this can be useful for everyone. Remember though, this CodeIgniter template parser class is very basic, and this post is aiming for those who do not know what a parser is. At the end of this post, I will give a few links to known template libraries out there, that can be more powerful.
For your reference, here is how EllisLabs describes the CodeIgniter Template Parser Class:
CodeIgniter Template Parser Class enables you to parse pseudo-variables contained within your view files. It can parse simple variables or variable tag pairs.
With this being said, if any of you have ever heard of Smarty template engine, or have ever worked with it, then it should be a breeze to understand. Let’s take a look at a very simple example. Let’s say we work for social network ‘X’, and the designer does not feel comfortable using files with PHP on it. An easy way to make this transition would be to have some kind of templating engine. That way, the designers will not be afraid of breaking essential code for any of the scripts, and well on their way to modifying the websites design through their CSS files. In our example, we will assume that we have our view for a profile page. This view can be very generic and let’s see how: