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.

Important

The Template Parser Class is not a full-blown
template parsing solution. We’ve kept it very lean on purpose in order
to maintain maximum performance.

The first parameter contains the name of the view
file (in this example the file would be called
blog_template.php), and the second parameter contains an associative
array of data to be replaced in the template. In the above example, the
template would contain two variables: {blog_title} and {blog_heading}

There is no need to “echo” or do something with the data returned by
$this->parser->parse(). It is automatically passed to the output class
to be sent to the browser. However, if you do want the data returned
instead of sent to the output class you can pass TRUE (boolean) as the
third parameter:

The above example code allows simple variables to be replaced. What if
you would like an entire block of variables to be repeated, with each
iteration containing new values? Consider the template example we showed
at the top of the page:

In the above code you’ll notice a pair of variables: {blog_entries}
data... {/blog_entries}. In a case like this, the entire chunk of data
between these pairs would be repeated multiple times, corresponding to
the number of rows in the “blog_entries” element of the parameters array.

Parsing variable pairs is done using the identical code shown above to
parse single variables, except, you will add a multi-dimensional array
corresponding to your variable pair data. Consider this example:

If you provide a string substitution parameter when an array is expected,
i.e. for a variable pair, the substitution is done for the opening variable
pair tag, but the closing variable pair tag is not rendered properly:

You do not have to use variable pairs to get the effect of iteration in
your views. It is possible to use a view fragment for what would be inside
a variable pair, and to control the iteration in your controller instead
of in the view.