I need to add a new field “Source” with a default text “No” to all pages with the template “entry” what is no problem, also to save the page in the panel . Since this concerns a lot of pages, is there a way to do the “Save Page” automatically instead of manually save every page new?
// Blueprint entry.yml
source:
label: Source
type: text
default: No
// Template entry.php
Source: <?= $page->source() ?>
Thanks a lot in advance !
You can do this programmatically, using $page->update()
.
https://getkirby.com/docs/cheatsheet/page/update
1 Like
FYI: I often adjust the template in such cases:
// Template entry.php
Source: <?= $page->source()->or("No") ?>
2 Likes
Thanks a lot @thguenther thats a nice way too ! Does or() stand for override ?
You can read more about the ->or()
helper here: https://getkirby.com/docs/cheatsheet/field-methods/or
“Checks if the field is empty and returns an alternative value in this case”.
1 Like
Thank you, this seems very useful !