<p>You can access your plugin via</p>

<pre><code>Plugin::getInstance()
</code></pre>

<p>You can then access its components defined by <code>setComponents</code></p>

<pre><code>Plugin::getInstance()-&gt;componentName
</code></pre>

<p>Or </p>

<pre><code>Plugin::getInstance()-&gt;get('componentName')
</code></pre>

<p>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 <code>Plugin Variable</code></p>

CC BY-SA 4.0
2019-02-25T18:35:44.037Z
2019-02-25T18:35:44.037Z
Robin Schambach
<p>I want to access a variable created in Plugin itself. In Craft 2, it could be simply done by <code>craft()-&gt;pluginName-&gt;getVar()</code> but I couldn't find a way in Craft 3. I have tried <code>Craft::$app-&gt;pluginName-&gt;getVar()</code> but that throws an error.</p>

<plugin-development>
How to access Plugin Variable in Plugin?
# How to access Plugin Variable in Plugin?

(Asked by: username_0 on 2019-02-25)

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.

**Tags:** plugin-development


---

## 1 answers

### Answer by username_1 on 2019-02-25. Score: 2 | Accepted answer

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


---

