Page 1 of 1
Registering Smarty plugins for both frontend and admin
Posted: Wed Feb 11, 2015 9:34 am
by kristoftorfs
When I register a Smarty plugin in my module installation the plugin works perfectly on the frontend, but when I try to use them in the admin interface it keeps giving me an "unknown tag" error.
I tried to set the $usage argument of RegisterSmartyPlugin to 0, 1 and 2, but neither one of them seems to solve the problem.
Re: Registering Smarty plugins for both frontend and admin
Posted: Wed Feb 11, 2015 3:35 pm
by calguy1000
Register your smarty plugins in your constructor.
but check to make sure that smarty has been initialized first.
i.e:
$smarty = cmsms()->GetSmarty();
if( $smarty ) {
$smarty->register_function('myfunction',$mycallable);
// note your plugin is now registered and available to all modules.
}
Re: Registering Smarty plugins for both frontend and admin
Posted: Wed Feb 11, 2015 3:42 pm
by kristoftorfs
Okay, thanks.
But why is the $usage argument in CMSModule::RegisterSmartyPlugin then?
It doesn't seem like it's being used...
Re: Registering Smarty plugins for both frontend and admin
Posted: Wed Feb 11, 2015 4:04 pm
by calguy1000
RegisterSmartyPlugin is for registering a smarty plugin for your module name so that you can do something like this:
{MyModule}.
It's argument is whether or not to register that plugin dynamically (the default) which would be usually called in the InitializeFrontend() method or in the constructor.
When registering a plugin statically, (for when you want your module to lazy load). you call RegisterModulePlugin(true); in the install method.