I'm trying to use a template to parse through nested data, but some of the child data has the same variable names as the parent. In the example below I'd like to print a list of shows and then a list of the episodes for each show, but the id, title, & description are parsed and given the parent data.
$data = array(
array(
'id' => 1,
'title' => 'LOST',
'description' => 'Best. Show. Ever',
'episodes' => array (
array (
'id' => 1001,
'title' => 'Pilot',
'description' => 'The one where the plane crashes.'
),
array (
'id' => 1002,
'title' => 'Dr. Jack',
'description' => 'Jack saves everyone.'
)
),
),
array(
'id' => 2,
'title' => 'Seinfeld',
'description' => 'Funniest. Show. Ever',
'episodes' => array (
array (
'id' => 2001,
'title' => 'Pilot',
'description' => 'The one where it wasn\'t funny yet.'
),
array (
'id' => 2002,
'title' => 'Kramer',
'description' => 'Kramer isn\'t that funny yet either.'
)
),
),
);
$tags = '<h1>{title}</h1>
<p>{description}</p>
<h2>Episodes:</h2>
<ul>
{episodes}
<li><em>{id}: {title}</em> {description}</li>
{/episodes}
</ul>';
$output = $this->EE->TMPL->parse_variables( $tags, $data );
echo $output;
?>
This generates the output below:
<h1>LOST</h1>
<p>Best. Show. Ever</p>
<h2>Episodes:</h2>
<ul>
<li><em>1: LOST</em> Best. Show. Ever</li>
<li><em>1: LOST</em> Best. Show. Ever</li>
</ul><h1>Seinfeld</h1>
<p>Funniest. Show. Ever</p>
<h2>Episodes:</h2>
<ul>
<li><em>2: Seinfeld</em> Funniest. Show. Ever</li>
<li><em>2: Seinfeld</em> Funniest. Show. Ever</li>
How can I access the episode data? If the field names are different it works just fine, but this data is coming from a web service that is not easily changed.