[eluser]Aken[/eluser]
There's two ways I've found you can do this:
The first way is kind of a fun trick, but may not be the most reliable. The template parser library goes through the loop of data to parse in order. You can double brace a variable and it will be parsed twice, as long as you put your data variables in the correct order. Example:
Code:
// VIEW
Here is the replaced variable: {{varname}}
// CONTROLLER
$this->load->library('parser');
$data = array(
'varname' => 'variable',
'variable' => 'replaced variable!',
);
$this->parser->parse('template', $data);
What happens is the variable {varname} is replaced, leaving the variable structure {variable} left in the view. Then, on the next iteration, {variable} is replaced with the appropriate content.
I'm not sure how fool proof this is, but it does heavily rely on having your variable put in a specific order, which may or may not be difficult in your situation.
The other method is to set any variables you want to use and pass them to a view. You then return the view as a string instead of loading it, and use $this->parser->parse_string() instead of parse().
Code:
// VIEW
<h1>Galleries</h1>
<?php foreach ($galleries as $g): ?>
<div>
{<?php echo $g; ?>}
{img}
{/<?php echo $g; ?>}
</div>
<?php endforeach; ?>
// CONTROLLER
$this->load->library('parser');
$viewdata = array(
'galleries' => array('vacations', 'portraits'),
);
// Return view as string, now filled with proper template variables.
$template = $this->load->view('template', $viewdata, true);
$replace = array(
'vacations' => array(
array('img' => 'vacation img'),
),
'portraits' => array(
array('img' => 'portrait img'),
),
);
// Parse the view string, instead of a standard view. Works the same way.
$this->parser->parse_string($template, $replace);
Hope that helps you out.