0

I have some functions in another plugin that I'd like to use. For example, I'm using the shortcodes plugin, and it has a function shortcode_atts that I want to use in my plugin.

4

If the method you want to access is public and in another service file, you could access it via the service layer:

craft()->theOtherPluginService->method();

The method you are using above, the Scope Resolution Operator should work fine without declaring the \Craft namespace, as the plugins should already be loaded into the Craft namespace. It's used for accessing static and constant methods:

ClassName::method()

In cases where you may be loading a library that is not in the Craft namespace, the syntax you're using above would be needed, where you declare the full namespace:

\SomeOtherNameSpace\ClassName::method()
| improve this answer | |
  • Thanks for the in depth answer, Ben! I did see the way you're showing above. However, I actually think using use \Craft\Whatever as Mything below the namespace declaration is a working and clean way of doing it. Then you can just Mything::method() – Ryan Oct 12 '14 at 16:07
  • Sounds good Ryan. I realize I was using PluginName::method() in my first example instead of the appropriate ClassName::method() (updated above). I agree that when necessary using the use operator below the namespace is cleaner than the full namespace in the code. – Ben Parizek Oct 12 '14 at 19:53
1

I did it this way:

\Craft\Shortcode::shortcode_atts()

Seems directly accessing it via namespace would be correct (assuming!)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.