Ability to nest plugin calls
Posted: 23 January 2008 12:44 PM   [ Ignore ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

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]

Profile
 
 
Posted: 23 January 2008 12:48 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

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}

Profile
 
 
Posted: 23 January 2008 01:00 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

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);

Profile
 
 
Posted: 23 January 2008 01:45 PM   [ Ignore ]   [ # 3 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15846
Joined  06-03-2002

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

 Signature 
Profile
MSG
 
 
Posted: 23 January 2008 04:11 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

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…

Profile
 
 
Posted: 23 January 2008 04:23 PM   [ Ignore ]   [ # 5 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15846
Joined  06-03-2002

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.

 Signature 
Profile
MSG
 
 
Posted: 23 January 2008 05:03 PM   [ Ignore ]   [ # 6 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

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.

File Attachments
yui_plugin.zip  (File Size: 9KB - Downloads: 104)
Profile
 
 
Posted: 23 January 2008 05:24 PM   [ Ignore ]   [ # 7 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15846
Joined  06-03-2002

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.

 Signature 
Profile
MSG
 
 
Posted: 23 January 2008 05:43 PM   [ Ignore ]   [ # 8 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

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

Profile
 
 
Posted: 23 January 2008 05:48 PM   [ Ignore ]   [ # 9 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15846
Joined  06-03-2002

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

 Signature 
Profile
MSG
 
 
Posted: 24 January 2008 10:05 AM   [ Ignore ]   [ # 10 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

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}

Profile
 
 
Posted: 24 January 2008 10:23 AM   [ Ignore ]   [ # 11 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15846
Joined  06-03-2002

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}

 Signature 
Profile
MSG
 
 
Posted: 24 January 2008 11:56 AM   [ Ignore ]   [ # 12 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

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

Profile
 
 
Posted: 24 January 2008 12:02 PM   [ Ignore ]   [ # 13 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15846
Joined  06-03-2002

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.

 Signature 
Profile
MSG
 
 
Posted: 24 January 2008 01:57 PM   [ Ignore ]   [ # 14 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

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

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65030 Total Logged-in Users: 32
Total Topics: 82119 Total Anonymous Users: 17
Total Replies: 441331 Total Guests: 167
Total Posts: 523450    
Members ( View Memberlist )
Newest Members:  cfvicdreamNOIRgmonCooperWrightReedsmeenoiYang.JianuoioitsukiNathan Hammondalexcig