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

Ability to nest plugin calls

Development and Programming

Phoebe's avatar
Phoebe
58 posts
17 years ago
Phoebe's avatar Phoebe

At the moment the system gets confused if I call the same plugin within itself. I wanted to do this in the yui plugin, eg.

{exp:yui:load:tabs ....}

{tab}
   ....
   {exp:yui:load:calendar ..}{/exp:yui:load}

{/tab}

{tab}
    ...
    etc.
{/tab}

{/exp:yui:load}

Looking at core.template.php it is searching for the first instance of the closing tag. I changed it to look for the last instance and it seems to work, but it may break something else! Be good to be able to nest plugins.

Code changed on line 690 to use strrpos instead of strpos:

$out_point = strrpos($this->fl_tmpl, $cur_tag_close);

[Mod edit: Moved to plugin support forum as this feature already exists]

       
Phoebe's avatar
Phoebe
58 posts
17 years ago
Phoebe's avatar Phoebe

No - of course it is not that easy! Tried a more complex example and it doesn’t work:

{exp:yui:load type="menu"}{/exp:yui:load}

{exp:yui:load type="tabs" ....}

{tab}
   ....
   {exp:yui:load type="calendar" ..}{/exp:yui:load}

{/tab}

{tab}
    ...
    etc.
{/tab}

{/exp:yui:load}
       
Phoebe's avatar
Phoebe
58 posts
17 years ago
Phoebe's avatar Phoebe

Take 2:

// need to decide if looking for first or last instance of the tag.
                
                // if there is another opening of this same tag before the next closing one, then look for the last tag
                
                $first_open=&strpos;($this->fl_tmpl,LD.$tag);
                $first_close=   &strpos;($this->fl_tmpl, $cur_tag_close);
                            
                
                if ($first_close<$first_open)
                   $out_point=$first_close;
                else 
                    $out_point = strrpos($this->fl_tmpl, $cur_tag_close);
       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Of course you can nest plugins (see Nested Plugins heading). Explain what you mean by “At the moment the system gets confused”.

       
Phoebe's avatar
Phoebe
58 posts
17 years ago
Phoebe's avatar Phoebe

You can’t nest a call to the same function in the plugin as it assumes that the next closing tag for this plugin/function is the correct one.

This works: {exp:myplugin:func1}

{exp:myplugin:func2}

{/exp:myplugin:func2}

{/exp:myplugin:func1}

This does not

{exp:myplugin:func1}

{exp:myplugin:func1}

{/exp:myplugin:func1}

{/exp:myplugin:func1}

You could argue that this is bad plugin design to want to call nested functions…

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones
You could argue that this is bad plugin design to want to call nested functions…

Yes, lol. I didn’t catch that you were using the same method, as the tags had an additional segment. I instantly read it as calling ‘tabs’, ‘calendar’, etc. of your ‘load’ plugin. But to give specific advice, I’d need to have a better of idea of what problem you are solving that led you to try that in the first place.

       
Phoebe's avatar
Phoebe
58 posts
17 years ago
Phoebe's avatar Phoebe

Here is an example that works (because I hacked core.template.php)

http://demo.savemybacon.com/index.php/todo/yui_test

(needs login, uid: demo, password: demodemo)

Here is one without the hack

http://www.ggjump.com/index.php/site/yui_test/

Have attached plugin and template.

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

The simple solution to me would be to make variables for your load tag that the load tag can parse instead of calling the same tag over and over again.

       
Phoebe's avatar
Phoebe
58 posts
17 years ago
Phoebe's avatar Phoebe

Yes - just need to think if there is a case of nesting the same yui object inside itself. table within a table?

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Since your plugin will control how it parses variables, that shouldn’t be a problem.

       
Phoebe's avatar
Phoebe
58 posts
17 years ago
Phoebe's avatar Phoebe

So if I used your idea of variables, what would this look like?

{exp:yui:load type="tabs" name="mytabs"}

{tab}
   exp:yui:load type="calendar" name="mycal"}
    {/exp:yui:load}
{/tab}


{/exp:yui:load}
       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

It could look like anything you want–you’re doing the parsing afterall. One possibility:

{exp:yui:load type="tabs" name="mytabs"}

{tab}
    {load type="calendar" name="mycal"}
{/tab}

{/exp:yui:load}
       
Phoebe's avatar
Phoebe
58 posts
17 years ago
Phoebe's avatar Phoebe

Presumably this would be faster as I would only be creating one instance of the plugin class?

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

It would be more memory efficient since there will be fewer objects instantiated - the speed will determine more on how efficiently you parse your own variables.

       
Phoebe's avatar
Phoebe
58 posts
17 years ago
Phoebe's avatar Phoebe

Thanks for your advice. Will recode when I have the time to get my head around it!

       

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.