CodeIgniter Forums
Template Parse Class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Template Parse Class (/showthread.php?tid=67726)



Template Parse Class - MoFish - 04-01-2017

Hi,

I'm wondering if anyone can help.

I'm trying to create a little render of mark-up using the parse_template class and am a little stuck.

To demonstrate my crazy thinking, I have made the following array in my controller.

PHP Code:
$data = array(
 
'heading' => array(
 array(
 
'item' => array(
 array(
'html' => '<img src="{image}" alt="{alternative}" />''image' => 'source.jpg''alternative' => 'Hello wolrd'),
 array(
'html' => '<img src="{image}" alt="{alternative}" />''image' => 'source.jpg''alternative' => 'Hello wolrd'),
 ),
 ),
 ),
 
'footer' => array(
 array(
 
'item' => array(
 array(
'html' => '<p>{value}</p>''value' => 'hello from the footer x1'),
 array(
'html' => '<p>{value}</p>''value' => 'hello from the footer x2'),
 ),
 ),
 ), 
 ); 

and have the following tags in my view:

Code:
{heading}
{item}
{html}
{/item}
{/heading}

I parse the template which outputs the following mark-up to my browser which in theory is correct, however I want to go a step further and then have it replace {image}, {alternative}, and {value} with the value from the array. Its kind of like a double parse. I've tried to get it working using parse_string without success. Any ideas much appriciated. Tongue

Code:
<img src="{image}" alt="{alternative}" />
<img src="{image}" alt="{alternative}" />
               
<p>{value}</p>
<p>{value}</p>

Regards,

MoFish