-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Toggle fields do not save values if they are 'toggleable' #497
Labels
Comments
@rcheetah You had a bug in the field name, it has to be |
mahagr
added a commit
that referenced
this issue
Feb 16, 2021
@rcheetah Can you please test the fix? |
Oh man, sorry. What a messy test file by me. I actually run across this issue some weeks ago but didn’t have the time to file an issue, and then I mixed some things up. I tested the PR in two environments. Works perfectly! Thank you |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem/Bug
A field of type 'toggle' that is additionally
toggleable
will not be saved to the frontmatter, even if a value is set. The docs allow this field to betoggleable
.Grav.toggleable.toggle.bug.mp4
Why would someone need this setting on a 'toggle' field?
The short answer: 0 does not equal NULL.
A toggle field is semantically the best way to express a boolean setting. But – controversial statement incoming – in every programming language a boolean value has not two but three states. 'true', 'false' or 'NULL'/'undefined'. A toggleable 'toggle'-field will represent all three states.
Usage example
You can add a setting for every page-type (template) to override whether or not it renders its page.title value. Let's think of two page-types, 'text' and 'gallery'. By default it makes sense, that the 'gallery' does not render its page.title, it just shows nice images. The 'text' template would, by default, render the page.title. But if the user wants one specific gallery page to render its page.title, he can override the default setting by setting the value of
show_title
totrue
. In that scenario, the developer can't use the 'default' blueprint option, because he would then set the value for the 'text' and the 'gallery' page-type equally. But with a toggleable 'toggle' field the user can choose to override the rendering of the template.It is possible to solve that by using a three-way-switch (Yes, No, Auto), but that would clutter the frontmatter on most pages, because of an additional variable
show_title: auto
on every single page. Storing the value only if necessary would be cleaner, and I guess that’s kind of the purpose of toggleables.Example blueprint will be added in a minute.
The text was updated successfully, but these errors were encountered: