I normally don’t spam my plugins, but I know some people have been waiting for this one for some time.
Similar to the standard
when property, the WhenQuery plugin let’s you show and hide sections and fields. But it does so by evaluating an expression, which enables greater flexibility.
I’ve tried to design the expression language as powerful and easy as I could. If however you have a genius idea on how to simplify or empower it further please let me know, either here or on github.
Here’s an example blueprint:
label: Number of images
Good! You have at least 13 images in this post.
This will be a **great** post!
whenQuery: blocks ::count($.type = 'image') >= 13
This is awesome! Thank You so much! <3
@rasteiner wow, such a great plugin, i am literally using it everywhere!
thank you so much for your work on this.
it would be so cool if this plugin could handle conditional field visibility based on the page status as well. so for example: show fields, when the status is “listed” and hide fields when the status is “unlisted”. maybe this might be an interesting add-on for you?
That’s indeed an interesting idea, unfortunately there is no way I know of getting a reactive value to the page model in the panel.
I’ll add an issue to my repo anyway to keep track of it when I discover a way.
Turns out that sleeping helps.
0.2.2 gives you access to some of the model props. The page Status is one of those: https://github.com/rasteiner/k3-whenquery#model-variables
just saw this on github.
wow sooo good, thank you so much!
Great plug-in @rasteiner. I’d like to implement a feature toggle which means on site level there are certain toggle fields e.g. “feature-categories”. Then on page level an additional categories field shall be shown depending on the toggle value.
Would that be possible with whenQuery? It seems no as it gives “just” access to predefined variables, correct?
The plugin only has access to what the panel gives me. That is the current model content an some of its properties. Your idea would need access to another model’s content and that won’t work, unless you create something like a custom hidden field that receives its value from the backend.
But it seems like you don’t actually need to have it update in realtime, so what you want is probably more like “programmable blueprints”.
@rasteiner may i ask why
_template is available with the new file properties, but not with the new page properties? because i would actually love to show/hide fields based on the selected template of the page!
I simply forward the model properties that get sent by Kirby to the panel: kirby/Page.php at 04127160ed1ab8dc277763cd8ba4ebc5a097bc18 · getkirby/kirby · GitHub
And the template isn’t one of them for pages. I didn’t bother to much about the missing template property because I assumed that “showing/hiding fields and sections based on the template” would be primarily done by using different templates.
What’s the use case?
i am actually reusing sections & fields as described here. so this is where it makes sense. using the same section in two different blueprints. but controlling which fields within the section are visible based on the template of the page. hope that makes sense? it got quite late yesterday.
but anyway, i did find an alternative solution to my use case already. no need for you to dive into it more. i was more curious where these properties are coming from and now i know! thank you so much!