Hello,
I am trying to use a field value in my config file to add to a placeholder, but failing.
I have tried all of these:
$delay = $kirby()->site()->delay();
$delay = $site()->delay();
$delay = $page->site()->delay();
They all give me a white screen telling me this page isn’t working.
Any ideas?
Thank you,
Joke
There are some issues with this:
-
You cannot call kirby()
or site()
in the config, unless you wrap your code within the ready
option.
-
$kirby()
: either kirby()
or $kirby
(if $kirby
is defined), but not both, same for site()
.
-
How exactly are you using this in your config, could you please post the context?
Hi,
I looked at the option thing earlier, but I am not understanding how to use it properly. The link you added goes to getkirby.test, not the docs page.
I am using this variable to calculate a lead time of availability. The field contains a number (eg. 3) and then a date is calculated from that, and then placed in a placeholder.
$delay = $page->site()->delay();
$lead_time = strtotime('+' . $delay . ' week');
$day_of_week = date('N', $lead_time);
$to_tuesday = (7 - $day_of_week) + 2;
$new_work = strtotime(date('c', $lead_time) . ' + ' . $to_tuesday . ' days');
return [
'placeholders' => [
'new_work' => date('dS F, Y', $new_work),
]
];
Ah, sorry, I had my local copy open, fixed above.
Try:
return [
// other stuff
'ready' => function() {
$delay = site()->delay();
$lead_time = strtotime('+' . $delay . ' week');
$day_of_week = date('N', $lead_time);
$to_tuesday = (7 - $day_of_week) + 2;
$new_work = strtotime(date('c', $lead_time) . ' + ' . $to_tuesday . ' days');
return [
'placeholders' => [
'new_work' => date('dS F, Y', $new_work),
]
];
}
];
Wow! That’s amazing.
Thank you very much.