Blueprint option to not save empty fields

I just saw this and agree that the content text files can be a bit bloated sometimes:

Maybe we could introduce a new blueprint option, something like this:

fields:
  my_field:
    label: My field
    type: text
    keepEmpty: false

where keepEmpty: false would force the panel to skip fields that are empty.

If it’s not set it should fall back to keepEmpty: true, just like the way it works now.

Advanced - Maybe a more solid solution

Now not every field is a text field. Maybe we have a toggle and it should skip saving data when it’s false which is not the same thing as empty.

fields:
  my_field:
    label: My field
    type: text
    skip: false

This time around we have a skip option. It will simply skip the value if it matches the blueprint option. In this case it will not save the value if it’s false.

In both cases it should not save they key to the value, like the value has never been in the blueprint.

Feedback?

I have opened an Issue for this quite a while ago, but I don’t think it was understood what I meant and I didn’t really care enough to persist :wink: but yeah, I’m still in favour of some way to get rid of it.

Maybe introduce a thing like:

c::set('panel.remove-empty-fields', true);

Ahh. :slight_smile: I did not know about that one.

Your approach is a bit different. Your option is global. My suggestion is a blueprint option that could be set differently for different kind of fields.

Hm, and maybe slightly unrelated but still good to note:

var_dump(
  $page->name()->isNotEmpty(),
  $page->content()->has('name')
);

Would give two times false if there was no Name: in the content file, but does false true when it has.