We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Var Pairs

Development and Programming

ldewey's avatar
ldewey
1 posts
17 years ago
ldewey's avatar ldewey

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]

       
Jamie Poitra's avatar
Jamie Poitra
409 posts
17 years ago
Jamie Poitra's avatar Jamie Poitra

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.

       
Jamie Poitra's avatar
Jamie Poitra
409 posts
17 years ago
Jamie Poitra's avatar Jamie Poitra

Hey ldewey,

I talked to Paul about it and he says that, yes, the way you have done it is fine and perfectly acceptable in terms of the current EE and should work fine. However, EE 2.0 (no ETA) will inherit some of CI’s elegance in this area.

Jamie

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.