Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

defaultPluginHandler and block plugins.

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
calguy1000
Smarty Rookie


Joined: 27 Mar 2009
Posts: 25

PostPosted: Mon May 21, 2012 4:33 pm    Post subject: defaultPluginHandler and block plugins. Reply with quote

Hi.

I am using $smarty->registerDefaultPluginHandler() to handle unknown plugins in Smarty 3.1.8. I am using it two ways: a: to dynamically load plugins from a variety of sources... and b: to ignore unknown plugins when parsing a template.

my default plugin handler for case b: is simply:
Code:
public function _dummyDfltPluginHandler($name, $type, $template, &$callback, &$script, &$cachable)
{
   $callback = 'Smarty_CMS::_dflt_plugin';
   $cachable = '';
   return TRUE;
}


Smarty_CMS::_dflt_plugin is a simple plugin function that returns no output.

if you have a template like: {myblockplugin} .... {/myblockplugin}
the _dummyDfltPluginHandler is called for {myblockplugin} but not for {/myblockplugin}. Because of this of course a serious error is returned, which is exactly what I'm trying to prevent.

The call stack is:
Code:
Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "template:27" on line 131 "{cgsi_convert max_width=400 max_height=400 quality=30}{content}{/cgsi_convert}" unknown tag "cgsi_convertclose"' in /var/www/cms1_10/lib/smarty/sysplugins/smarty_internal_templatecompilerbase.php:627 Stack trace: #0 /var/www/cms1_10/lib/smarty/sysplugins/smarty_internal_templatecompilerbase.php(406): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown tag "cg...', 131) #1 /var/www/cms1_10/lib/smarty/sysplugins/smarty_internal_templateparser.php(2518): Smarty_Internal_TemplateCompilerBase->compileTag('cgsi_convertclo...', Array) #2 /var/www/cms1_10/lib/smarty/sysplugins/smarty_internal_templateparser.php(3111): Smarty_Internal_Templateparser->yy_r58() #3 /var/www/cms1_10/lib/smarty/sysplugins/smarty_internal_templateparser.php(3211): Smarty_Internal_Templateparser->yy_reduce(58) #4 /var/www/cms1_10/lib/smarty/sysplugins/smarty_internal_smartytemplatecompiler.php(105): Smarty_Interna in /var/www/cms1_10/lib/smarty/sysplugins/smarty_internal_templatecompilerbase.php on line 627


Is there a workaround/solution for this? I think the defaultPluginHandler should be called for all unknown plugins...

Thanks in advance.
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue May 22, 2012 6:43 pm    Post subject: Reply with quote

Your usage of the default plugin handler can't work.

Note that the default handler will be called several times looping through the different plugin types until it returns a call back.

See http://www.smarty.net/docs/en/api.register.default.plugin.handler.tpl

In your case you ignore the $type parameter and you return your callback on its first call where it tries to the type PLUGIN_FUNCTION.
Because of the reply with a callback Smarty assumes a function plugin and can not handle the closing tag.
Back to top
View user's profile Send private message
calguy1000
Smarty Rookie


Joined: 27 Mar 2009
Posts: 25

PostPosted: Wed May 23, 2012 6:31 pm    Post subject: Reply with quote

Okay, I can see how the defaultPluginHandler is called... and that's great. it solves a different problem I was having.

However, what i really need to do is to provide the same dumb plugin (which does nothing) to all unknown smarty plugins.

The regular defaultPluginHandler I am using will normally dynamically look in the database, or in some extra directories etc. to try to resolve plugins, and if that throws an error everything is good.

However, this is a case where I want all unknown plugins to do nothing. There will be no dynamic loading of plugins or anything in this particular case. And I do not know the type of those plugins. i.e: they could be function plugins, block compiler, or objects... I just need to have them silently ignored.

The only thing that seems to be giving me problems right now is block tags.

So either, I need to have the _defaultPluginHandler called for the myblockpluginclose thing for block tags, or a way to not have an exception thrown (an error list that I can ignore/delete would be fine).

Any thoughts?
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed May 23, 2012 8:22 pm    Post subject: Reply with quote

Currently I see only the option that you check in your default handler against a list of names for which it should return a callback any when $type is Smarty::PLUGIN_BLOCK
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP