From your example, the Global
handle is globalWebsite
and the field handle is freeTrialPeriodDays
.
So this should work in PHP:
$trialDays = \Craft::$app->getGlobals()->getSetByHandle('globalWebsite')->freeTrialPeriodDays;
You should probably do this in two steps so you can check that a Global
has been returned before you try to query the field value on it:
$myGlobal = \Craft::$app->getGlobals()->getSetByHandle('globalWebsite');
if ($myGlobal) {
$trialDays = $myGlobal->freeTrialPeriodDays;
} else {
$trialDays = 'some default value';
}
This can be simplified using the null coalescing operator like this:
$trialDays = \Craft::$app->getGlobals()->getSetByHandle('globalWebsite')->freeTrialPeriodDays ?? 'some default value';