Hi!
I’m trying to make a file section (images) required: true
to prevent a page being published without an image. Is required
working only on fields
? (Of course I’ll also check with isNotEmpty()
)
Thanks!
Hi!
I’m trying to make a file section (images) required: true
to prevent a page being published without an image. Is required
working only on fields
? (Of course I’ll also check with isNotEmpty()
)
Thanks!
I’d suggest using min: 1
instead: https://getkirby.com/docs/reference/panel/sections/files#limits
isNotEmpty()
will not work on a files section. Sections don’t save any data.
If it’s the only files section you can use $page->hasFiles()
. When using multiple files sections with different templates you can use $page->files()->template('yourtemplate')->count()
as a condition.
See this page for an explanation of the section/field difference: https://getkirby.com/docs/cookbook/setup/kirby-in-a-nutshell#sections-or-fields__files-section-vs-files-field
isNotEmpty()
instead of count()
would also work.
Thanks! I will try the min
option, completely forgot about that.