Hi!
I want to update a page from my plugin using $page->update() | Kirby CMS and now I’m stuck. I’d like to update a structured field, but I have no idea how my array (?) has to look to get this working.
The field is structured like so:
Podcasterchapters:
-
podcasterchaptertimestamp: 00:00:01
podcasterchaptertitle: Mein Titel2
Can someone help me? Thank you!
Thank you, that helped a lot! 
Hello,
I don’t understand how you do it?
I have copy the following code in my controllers:
<?php {
function addToStructure($page, $field, $data = array()){
$fieldData = page($page)->$field()->yaml();
$fieldData[] = $data;
$fieldData = yaml::encode($fieldData);
try {
page($page)->update(array($field => $fieldData));
return true;
} catch(Exception $e) {
return $e->getMessage();
}
}
}
It is not possible to update from the front at the moment.
In my template I put this form:
<?php foreach ($page->listing()->toStructure() as $listing): ?>
<div class="form-group">
<label for="headline">Date</label>
<input type="text" class="form-control" id="date" name="date" placeholder="date" value="<?= $listing->date() ?>">
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1">Description</label>
<textarea class="form-control" id="text" name="description" placeholder="description" rows="10"><?= $listing->description() ?></textarea>
</div>
<?php endforeach ?>
And my blueprints:
listing:
label: Historique
type: structure
fields:
date:
label: Date
type: text
width: 1/2
description:
label: Description
type: text
width: 1/2
Does that seem coherent to you?
Thanks
Putting just the function into your controller won’t do anything, a function only does something when it is called. So you have to integrate that into your form handling.
Ok I’m trying to adapt but I don’t have a very good php level.
Actually it makes sense.