-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Support for different selects based on object type (Block type/Page template/User role) #45
Comments
Thanks.
And I wonder if I could add different srcsets... That would be amazing. |
Pretty sure you should be able to something like this:
Doesn't belong to this issue tho? |
This is perfect, would love to see it in core - I guess it's not possible to implement as an additional plugin independent from KQL? |
nope, sadly would need to be integrated in KQL directly - similar to how I did it. |
I've made a push at TS types for KQL, supporting your extended If you are interested in using, testing or helping out, cool! Otherwise, thanks for the plugin. |
Really nice! I'll check it out when I've time to work on my personal site again. |
Seems like we all have the same issue – resolving relations inside blocks. For my personal use-case, I have created a custom Via the Kirby config, we can define, which blocks actually contain images: # /site/config/config.php
return [
'blocksResolver' => [
// Blocks that contain files fields
'files' => [
// Block name as key, field name as value
// Resolve the built-in `image` field of the `image` block
'image' => 'image'
]
]
]; But the |
@bastianallgeier @distantnative I'd love to hear what you think about my approach. If it suits your needs, I'll happily submit a PR. |
Sorry for the delay, but I actually really love the models idea! A PR would be great. |
Do you mind taking a look at the plugin I linked above as a base for the PR? Will of course add unit tests, but just asking for feedback on the general implementation as I haven't completely understood the Kql code yet 🙂 |
@tobimori sorry, I completely missd the link to your experiment. The code looks super straight forward. |
Just started looking into KQL and this one of the first issues i ran into. I know work is focused on releasing Kirby v4 and i can’t wait for it : ) To make KQL usable with blocks the support for different and custom block types should be added to the plugin. Reading the issues for KQL it seems that this causes at least a fair amount of headaches. |
The issue
I want to access different properties based on block types. For an image, I might want to generate a srcset and get the alt text, but other blocks don't have an image, so the query would fail.
The previous solution would be to create a Block model with Kirby, with a
toArray
function. This would result in my "queries" being in two different locations - half of it in my frontend, and everything related to a specific Block type etc. would be in my backend.Solution
I experimented with that idea here.
In short, I added a
models
property that allows to specify different selects based on the object type, similar to models in core.This is a quick-and-dirty proof-of-concept, but it works for what I've tested it. Feel free to take any code from that repository for adding this feature.
The text was updated successfully, but these errors were encountered: