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?
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,
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
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.