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

Need some help with single vars and pair vars in the same plugin

Development and Programming

Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

Here is the way I want the data to work:

{exp:myplugin}
v1 = {var1}
v2 = {var2}
{subvars}
  v3 = {var3}
  v4 = {var4}
{/subvars}

The subvars are an array and should be repeated for all the data, so I would see something like this:

v1 = foo
v2 = bar
  v3 = fliggle1
  v4 = flaggle1
  v3 = fliggle2
  v4 = flaggle2
  v3 = fliggle3
  v4 = flaggle3

Here is what I have and it isn’t quite working:

// process single vars
$tagdata = $FNS->prep_conditionals($TMPL->tagdata, $TMPL->var_single);

foreach ($TMPL->var_single as $key => $val)
{
    switch ($val)
    {
        case "total_files":
            $tagdata = $TMPL->swap_var_single($val, $this->total_files, $tagdata);
            break;
        case "cat_id":
            $tagdata = $TMPL->swap_var_single($val, $this->cat_id, $tagdata);
            break;
    }
}
        
$return = $tagdata;
        
foreach ( $this->sub_cats as $sub_cat )
{
    $tagdata = $FNS->prep_conditionals($TMPL->tagdata, $sub_cat);

    foreach ($TMPL->var_single as $key => $val)
    {
        switch ($val)
        {
            case "sub_cat_name":
                $tagdata = $TMPL->swap_var_single($val, $sub_cat['cat_name'], $tagdata);
                break;
            case "sub_cat_id":
                $tagdata = $TMPL->swap_var_single($val, $sub_cat['cat_id'], $tagdata);
                break;
        }
    }
            
    $return .= $tagdata;
}
$this->return_data = $return;

I have tried to find examples of this but I still don’t quite understand how all the processing occurs.

And I need to remove the tag pairs from my return value and I am not sure how to do that…$TMPL->remove_tag_pairs maybe?

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

OK, I have been playing with this and I really don’t get how it is supposed to work. I can’t figure it out from the existing code (too complicated). And the documentation is sooooo close to helping me out: http://expressionengine.com/docs/development/usage/template.html#single_pair

If only they had the code for this:

// Single Variable
{summary}

// Pair Variable
{category}

{/category}

// Conditional Variable
{if body != ""}

{/if}

That, to me, is an error in the docs, to show and example and then to show code below it, that doesn’t match.

If anyone could show me the code that would parse the above example, I would be extremely grateful.

Thanks

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

Whew, that was fun.

I managed to get it all working but who knows if it is the ‘correct way’.

It would still be nice if there was an example in the docs. Once I use my plugin a little, I will make a posting to the wiki so that others might benefit from it.

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

Erin,

There isn’t really a right way that I know of regarding sub variables within a variable pair. Its more a case of what works best for a given situation. I get the feeling that this post and your other post on outputting with weird results are really combined within your post on a plugin review? I’ll take a look at that tonight when I have a chunk of spare time to sit down with it and I’ll let you know what I might try to do differently.

Jamie

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

Yup, let me go make sure that post has the most up-to-date version of my plugin.

I do have it all working properly now, and I would ideally like to contribute it to the community, but before I release it, I thought a peer review might do me good.

Thanks

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

OK, post updated with most recent code.

       

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.