Oziris
March 7, 2017, 1:04pm
1
Can I abuse with another question ?
I created an array of “special days” that displays each value in my calendar.
<?php $fmoon = array('2017-02-11', '2017-03-12', '2017-04-11', '2017-05-10', '2017-06-09', '2017-07-09', '2017-08-07', '2017-09-06', '2017-10-05', '2017-11-04', '2017-12-03');?>
But the user want to be able to custom himself the dates. Can we do that with the default date picker ?
I mean adding as many dates as wanted ?
Take a look at the structure field: https://getkirby.com/docs/cheatsheet/panel-fields/structure
You can use it with a date field.
Oziris
March 7, 2017, 1:32pm
3
Cool, I did
fmoon:
label: Addresses
type: structure
width: 1/2
entry: >
{{date}}
fields:
date:
label: Date
type: date
but the call :
<?php $fmoon = $site->fmoon()->yaml(); ?>
<?php $fmoon = $site->fmoon()->toStructure(); ?>
doesn’t work
What do you mean by it doesn’t work? It does not deliver any results when you do a dump($fmoon)
? Do you get an error message?
Oziris
March 7, 2017, 3:02pm
5
I’m using an if to get a specific ID if the value correspond
<?php if (in_array($day, $fmoon)) { echo 'id="fmoon"';} ?>
The ID is displayed with my manual array but not with yaml()
or toStructure()
Which is not that surprising, because you don’t get a flat array, but a multidimensional one with the yaml()
method. You will see the structure if you dump the array as I suggested above. The toStructure()
method returns a collection, not an array.
<?php
$items = $site->fmoon()->toStructure();
$dates = [];
foreach($items as $item) {
$dates[] = $item->date('Y-m-d');
}
if (in_array($day, $dates)) { echo 'id="fmoon"';}