Hello,
I think it’s a bug :
In the panel, when I try to update a field on site.txt, Kirby update this field but erase all other fields.
This is the context :
I work on a widget to order the menu. I have a list of pages, sortable, and an hidden field with the list in yaml format. When I save the form kirby update the field “menu” of site.txt but it erase al others… It’s working on page.
This is the widget code :
<?php
# site/widgets/menu-order/menu-order.html.php
if (isset($_GET['menu-order-yaml'])) {
// this is not working
panel()->site()->update(array(
'menu' => $_GET['menu-order-yaml']
));
/* this is working
panel()->page('menu')->update(array(
'menu' => $_GET['menu-order-yaml']
));
*/
}
$menu = panel()->site()->menu()->yaml();
$items = array();
foreach ($menu as $item) {
$item = panel()->page($item['uri']);
$items[] = $item;
}
?>
<div id="menu-order" class="sortable">
<?php foreach($items as $item): ?>
<div class="item" data-uri="<?= $item->uri() ?>" data-visibility="true">
<?= $item->title() ?>
</div>
<?php endforeach ?>
</div>
<form class="" action="/panel/" method="get">
<textarea name="menu-order-yaml" id="menu-order-yaml"></textarea>
<fieldset class="fieldset buttons buttons-centered">
<input class="btn btn-rounded btn-submit" data-saved="Enregistré !" value="Enregistrer" type="submit">
</fieldset>
</form>
<script>
$('#menu-order').sortable({
update: function(event, ui) {
var menuorder = "";
$('#menu-order>.item').each(function(){
var uri = $(this).attr('data-uri');
var visibility = $(this).attr('data-visibility');
menuorder += "-\n uri: "+uri+"\n visibility: '"+visibility+"'\n";
})
$('#menu-order-yaml').val(menuorder);
}
});
</script>
This is not the best way to update a field, but from a widget, it’s the only one I found. Do you have other idea ?