Template Parser rser Class
The Template Parser Class enables you to parse pseudo-variables contained within your view files. It can parse simple variables or variable tag pairs. If you've never used a template engine, pseudo-variables look like this:
<html>
<head>
<title>{blog_title}</title>
</head>
<body>
<h3>{blog_heading}</h3>
{blog_entries}
<h5>{title}</h5>
<p>{body}</p>
{/blog_entries}
</body>
</html>
These variables are not actual PHP variables, but rather plain text representations that allow you to eliminate PHP from your templates (view files).
Note: CodeIgniter does not require you to u
{/blog_entries}
</body>
</html>
These variables are not actual PHP variables, but rather plain text representations that allow you to eliminate PHP from your templates (view files).
Note: CodeIgniter does not require you to use this class since using pure PHP in your view pages lets them run a little faster. However, some developers prefer to use a template engine if they work with designers who they feel would find some confusion working with PHP.
Also Note: The Template Parser Class is not not a full-blown template parsing solution. We've kept it very lean on purpose in order to maintain maximum performance.
Initializing the Class
Like most other classes in CodeIgniter, the Parser class is initialized in your controller using the $this->load->library function:
$this->load->library('parser');
Once loaded, the Parser library object will be available using: $this->parser
The following functions are available in this library:
$this->parser->parse()
This variable accepts a template name and data array as input, and it generates a parsed version. Example:
$this->load->library('parser');
$data = array(
'blog_title' => 'My Blog Title',
'blog_heading' => 'My Blog Heading'
);
$this->parser->parse('blog_template', $data);