Hi all,
Is it possible to access one plugin from within another? I don’t mean by nesting plugins within a template, but instead doing the work within the plugin code itself. It seems like the parse_type method of the typography class might do the job.
On a separate note, does anyone have any good advice on when a development situation calls for a module vs a plugin? It seems like this would be a good addition to the documentation.
Many thanks, as ever, Rob
You should be able to use one plugin inside another–depending on many things, of course. One, whether that plugin requires use of the TMPL or Template class. If so, you are likely out of luck–while you can access it, the other plugin will break.
But yes, since a plugin is a class, just test for like the Typography class. Assign a variable to represent the plugin, and then create the plugin class… and access it just like any other php class would, outside of EE.
RobJ25,
Definately possible. Though how useful it will be to you depends greatly on how the plugin’s functions are written. If the plugin functionality is abstracted from the main function that interfaces wtih the TMPL class then it will work out fairly well. If not then it may not be of much use to you.
I outlined how you would call a Plugin class within a function in another thread
If you have any questions or need details feel free to ask.
Jamie
Well, I’ll defer to you, of course, Derek. But my thinking was that if the plugin you are including is expecting to get data from the template class directly, and such data is not available, then it would return errors or nonsense.
Example: my custom member data plugin. It expects any number of parameters, which it gets from the TMPL class. I never provided a way to pass in parameters to the methods. So, to call my plugin directly from another plugin, module, etc just wouldn’t work, unless there is inside the TMPL class some parameters that can be passed to my plugin. I.e. I expect a “data” parameter–and if I don’t get one, my plugin just returns an empty string. I get my “data” parameter straight from the TMPL class. How would another module supply that parameter to my plugin?
Now, other plugins, etc. may not have that issue, and indeed, I can see a plugin that gets tag data from the TMPL class working anyway, as it just would get the same data as the calling class (I think), and go from there.
Or have I missed some fundamental concept? I think Jamie is talking about the same thing I am in this thread.
With my plugin, though, it wouldn’t be too hard to adjust so it would play nice with others.
Well your plugin methods can easily be modified to accept parameters. Just provide defaults when nothing is passed directly to the methods, which will be the case when it’s called from a tag.
function foo($bar = '', $bat = '')
But if you are referencing the global $TMPL object, it will not have changed from merely calling another class in another file.
pi.foo.php:
class Foo {
function Foo()
{
if (! class_exists('Bar'))
{
require PATH_PI.'pi.bar'.EXT;
$bar = new Bar;
}
}
}
pi.bar.php:
class Bar {
function Bar()
{
global $TMPL;
print_r($TMPL);
}
}
Tag in the template:
{exp:foo param_1="value_1" param_2="value_2"}
This is the tagdata.
{/exp:foo}
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.