1

I want to access a variable created in Plugin itself. In Craft 2, it could be simply done by craft()->pluginName->getVar() but I couldn't find a way in Craft 3. I have tried Craft::$app->pluginName->getVar() but that throws an error.

2

You can access your plugin via

Plugin::getInstance()

You can then access its components defined by setComponents

Plugin::getInstance()->componentName

Or

Plugin::getInstance()->get('componentName')

If you just want to get properties of your main plugin class it's the same way as above. Not sure what you mean exactly by Plugin Variable

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.