Hey man,
but seems very heavy structural that i can’t get in its hearth!
don’t be afraid of it. Try it. It can be so easy and simple.. and otherwise so powerfull and (your right) heavily complex.
ok, i will try to give you a sample.
you want an output like this
<div>
<h1>title</h1>
<div>
<h3>title 1</h3>
<p>some text for the first entry</p>
</div>
<div>
<h3>title 2</h3>
<p>some text for the second entry</p>
</div>
</div>
the source is an array like this
<?php
$data = array(
0 => array(
'title' => 'title 1',
'text' => 'some text for the first entry'
),
1 => array(
'title' => 'title 2',
'text' => 'some text for the second entry'
)
);?>
By the selfmade-way you need two templates
outer_tpl:
<div>
<h1>Title</h1>
[+inner_output+]
</div>
inner_tpl:
<div>
<h3>[+title+]</h3>
<p>[+text+]</p>
</div>
than you need the logic to handle the templates and source.
<?php
function myReplaceFunc( $tpl, $data )
{
foreach( $data as $ph => $val)
{
$retval = str_replace('[+'.$ph.'+]',$val, $tpl);
}
return $retval;
}
$inner_output ='';
$inner_tpl = file_get_contents( 'inner_tpl' );
foreach( $data as $dataset )
{
$inner_output .= myReplaceFunc($inner_tpl, $dataset );
}
$output ='';
$outer_tpl = file_get_contents( 'outer_tpl' );
$output .= str_replace('[+inner_output+]', $inner_output, $outer_tpl );
return $output;
?>
often it looks like that or similar like that.... or completely different.. anyhow, the way to doing this is similar... ok, this kind of bullshit is really _not_ a sample for nice code. But good enough to show "how to breaking fingers".
Ok, i don’t know what you think, but i am can imagine how to waste my time by doing some sweeter things.
The smarty-way is much easier
<?php
$smarty->assign( 'data', $data );
$smarty->display( 'tempate' );
?>
Template
<div>
<h1>title</h1>
{foreach from=$data item=i}
<div>
<h3>{$i.title}</h3>
<p>{$i.text}</p>
</div>
{/foreach}
</div>
wow! how fast is it! And you have much more "built-in"-possiblities in the template.
MuchMore as everyone of us could provide without spending hundreds of hours to build up an template-engine. Thats the reason why i am vote for smarty.
bye, Stefan
PS: sorry for my horrible english-spelling and i wont to decry the work of anyone.