I am building a Module and i am wanting to be able to do this in the template
<ul>
{comments}
<li>{test_comment}</li>
<li>{test_extra}</li>
{/comments}
</ul>
I have got the below code working with the above, but it feels like a hack their has to be a better way. Why cant i just past a assciated array to a var called $comments and have it work? (Like it does in CodeIgniter)
foreach ($TMPL->var_pair as $key => $val)
{
//$TMPL->tagdata = $TMPL->swap_var_pairs(’comments’, ‘comments’, $TMPL->tagdata);
$matches = $TMPL->fetch_data_between_var_pairs($TMPL->tagdata, $key);
$output = ‘’;
for($x=0; $x < count($test_comments); $x++ )
{
$template = $matches;
$template = $TMPL->swap_var_single(’test_comment’, $test_comments[$x], $template );
$output .= $TMPL->swap_var_single(’test_extra’, $test_extras[$x], $template );
}
$TMPL->tagdata = preg_replace( “/”.LD.preg_quote($key).RD."(.*?)”.LD.SLASH.$key.RD."/s", $output, $TMPL->tagdata);
[Moderator Edit: Moved to Module Tech Assistance forum, and added [code][/code] blocks for legibility]
Idewey,
I assume you have already looked at the core.template.php file for ideas?
What you have done looks pretty close to the way its being done there. EE isn’t a framework like CodeIgniter so when developing modules, plugins, and the like you aren’t as insulated from the general workings of PHP.
You may be able to reuse more of the template functions though. For instance there is a swap_var_pairs function though it looks like it might possibly be a little to specialized for your needs. It is only used for the date heading stuff in the entries tag from what I can tell.
Jamie
EDIT: It’s CodeIgniter, bad Jamie.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.