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:
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.