Answers.Body: <p>When searching the Craft 3.5.x docs for <code>siteName</code>, I see references to <code>Global Variables</code> and <code>General Config Settings</code>. Screenshot: <a href="https://cln.sh/egvIXhxZSzaFjeCgNLxX" rel="nofollow noreferrer">https://cln.sh/egvIXhxZSzaFjeCgNLxX</a></p>
  <p>However, AFAICT, it works differently for modules/plugins. As per the Sites section in the Craft 3.5.x Class Reference docs at <a href="https://docs.craftcms.com/api/v3/craft-services-sites.html" rel="nofollow noreferrer">https://docs.craftcms.com/api/v3/craft-services-sites.html</a>, you would do something like one of the following:</p>
  <pre class="lang-php prettyprint-override"><code>Craft::$app-&gt;sites-&gt;currentSite-&gt;name;
  Craft::$app-&gt;sites-&gt;primarySite-&gt;name;
  Craft::$app-&gt;sites-&gt;getSiteByHandle('default')-&gt;name;
  Craft::$app-&gt;sites-&gt;getSiteById(1)-&gt;name;
  </code></pre>
  <p>I'm getting the <code>name</code> part because I'm using PhpStorm with autocomplete set up as per article at <a href="https://nystudio107.com/blog/auto-complete-craft-cms-3-apis-in-twig-with-phpstorm" rel="nofollow noreferrer">https://nystudio107.com/blog/auto-complete-craft-cms-3-apis-in-twig-with-phpstorm</a></p>
  <p>Screenshot of autocomplete in action: <a href="https://cln.sh/T77W1Y69SmR3qPUPv0sb" rel="nofollow noreferrer">https://cln.sh/T77W1Y69SmR3qPUPv0sb</a></p>
  <p>I'm successfully using <code>Craft::$app-&gt;sites-&gt;getSiteById(1)-&gt;name;</code> in one of my custom modules.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-06T19:28:13.720Z
Answers.Text: Much appreciated! I never used multiple sites before, so I didn't even think of having to access it by current site. thank you thank you!!
Answers.UserDisplayName: Cat Named Dog
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-06T21:48:22.323Z
Answers.Text: In support of this answer, the `siteName` Twig global is just a shortcut to the current site's `->name`. See https://github.com/craftcms/cms/blob/de7fbb5043e4d5da4b3fb5030c3882188e201c0e/src/web/twig/Extension.php#L1312
Answers.UserDisplayName: Evan Warner
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-07T07:48:20.047Z
Answers.Text: And in more support of this answer, `siteName` and `siteUrl` have been [deprecated from 3.6](https://github.com/craftcms/cms/blob/3.6/CHANGELOG.md#deprecated) :)
Answers.UserDisplayName: Oli
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-07T14:38:59.733Z
Answers.Text: @Oli So I SHOULD actually just use the `Craft::$app->config->general->siteName` and not what setting is in the CP?
Answers.UserDisplayName: Cat Named Dog
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-07T21:56:48.367Z
Answers.Text: @good_afternoon: You can see [here](https://github.com/craftcms/cms/blob/de7fbb5043e4d5da4b3fb5030c3882188e201c0e/src/web/twig/Extension.php#L1312) from the source code how the ``siteName`` twig variable is being set. As mentioned in the answer,  ``Craft::$app->getSites()->getCurrentSite()->name`` will be equivalent.
Answers.UserDisplayName: RitterKnight
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-07T22:08:53.590Z
Answers.Text: The thing [deprecated](https://github.com/craftcms/cms/blob/3.6/src/config/GeneralConfig.php#L1233) is setting ``siteUrl`` and ``siteName`` from [``config/general.php``](https://craftcms.com/docs/3.x/config/config-settings.html) so you should avoid calling the config class where it gets the data from.
Answers.UserDisplayName: RitterKnight
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-06T19:22:28.287Z
Answers.LastActivityDate: 2020-12-07T14:44:12.500Z
Answers.LastEditDate: 2020-12-07T14:44:12.500Z
Answers.UserDisplayName: Andrea DeMers
Body: <p>In templates I can do something like <code>{{siteName}}</code>. But how do I retrieve this in a module?</p>
  <p>I've tried:</p>
  <p><code>Craft::$app-&gt;config-&gt;siteName</code></p>
  <p>I can grab my custom globals via <code>Craft::$app-&gt;globals</code>, but the class reference doesn't say anything about the defaults like <code>siteName</code></p>
  
Tags: <craft3><modules><globals>
Title: How do I get the siteName in a module (Craft 3)
ThreadText: # How do I get the siteName in a module (Craft 3)
  
  (Asked by: username_0 on 2020-12-06)
  
  In templates I can do something like `{{siteName}}`. But how do I retrieve this in a module?
  
  I've tried:
  
  `Craft::$app->config->siteName`
  
  I can grab my custom globals via `Craft::$app->globals`, but the class reference doesn't say anything about the defaults like `siteName`
  
  **Tags:** craft3, modules, globals
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-12-06. Score: 4 | Accepted answer
  
  When searching the Craft 3.5.x docs for `siteName`, I see references to `Global Variables` and `General Config Settings`. Screenshot: <https://cln.sh/egvIXhxZSzaFjeCgNLxX>
  
  However, AFAICT, it works differently for modules/plugins. As per the Sites section in the Craft 3.5.x Class Reference docs at <https://docs.craftcms.com/api/v3/craft-services-sites.html>, you would do something like one of the following:
  
  ```php
  Craft::$app->sites->currentSite->name;
  Craft::$app->sites->primarySite->name;
  Craft::$app->sites->getSiteByHandle('default')->name;
  Craft::$app->sites->getSiteById(1)->name;
  
  ```
  
  I'm getting the `name` part because I'm using PhpStorm with autocomplete set up as per article at <https://nystudio107.com/blog/auto-complete-craft-cms-3-apis-in-twig-with-phpstorm>
  
  Screenshot of autocomplete in action: <https://cln.sh/T77W1Y69SmR3qPUPv0sb>
  
  I'm successfully using `Craft::$app->sites->getSiteById(1)->name;` in one of my custom modules.
  
  > **Comments:**
  > **username_0**: Much appreciated! I never used multiple sites before, so I didn't even think of having to access it by current site. thank you thank you!!  
  > **username_2**: In support of this answer, the `siteName` Twig global is just a shortcut to the current site's `->name`. See https://github.com/craftcms/cms/blob/de7fbb5043e4d5da4b3fb5030c3882188e201c0e/src/web/twig/Extension.php#L1312  
  > **username_3**: And in more support of this answer, `siteName` and `siteUrl` have been [deprecated from 3.6](https://github.com/craftcms/cms/blob/3.6/CHANGELOG.md#deprecated) :)  
  > **username_0**: @username_3 So I SHOULD actually just use the `Craft::$app->config->general->siteName` and not what setting is in the CP?  
  > **username_4**: @good_afternoon: You can see [here](https://github.com/craftcms/cms/blob/de7fbb5043e4d5da4b3fb5030c3882188e201c0e/src/web/twig/Extension.php#L1312) from the source code how the ``siteName`` twig variable is being set. As mentioned in the answer,  ``Craft::$app->getSites()->getCurrentSite()->name`` will be equivalent.  
  > **username_4**: The thing [deprecated](https://github.com/craftcms/cms/blob/3.6/src/config/GeneralConfig.php#L1233) is setting ``siteUrl`` and ``siteName`` from [``config/general.php``](https://craftcms.com/docs/3.x/config/config-settings.html) so you should avoid calling the config class where it gets the data from.  
  
  ---
  
  