I just followed the guide on custom blocks here for creating a button block type. Now, the example uses url as type which I thought replicates the functionality of normal Kirby link tags. Instead, this uses URL and marks an internal Kirby link (just the page name) as invalid.
How would I create a component that allows for internal Kirby links as well as external URLs? Is it possible?
One option would be to use a radion field which let’s you select if it is an internal or external link and then show a pages field or a url field depending on the selection, similar to how the image block works.
Hm, while that would certainly work I hoped for a better solution like the normally used link handler in Kirby that can just auto-detect which type of link is entered… it’s not very user friendly with the radio option handler.
I don’t need to store it necessarily, I don’t mind to be honest. I hoped for a solution that exists in Kirby already instead of replicating Kirby’s own behaviour to get the exact same functionality in Kirby Blocks that already exists elsewhere (any textarea, any writer field).
I understand where you are coming from, but I would argue that these are different use cases. In your blocks field, you would ideally just store the value, i.e., either a URL or a page id in your field, not a rendered link or a kirbytag. Then in your frontend snippet, you would then output either the URL in an anker tag directly, or in case of a page or even file id, convert the value to a page object and then render the link with the page/file URL (or even just the id as relative link).
Thanks, so there’s simply no solution in Kirby to reuse the internal logic of it, right @texnixe? Then I’ll recreate it in my snippet, shouldn’t be too much of work. Just hoped to not have to duplicate the functionality, hence the question initially.
In regards to the “how to store the data” discussion: In a context of a WYSIWG page (and all blocks pages are such ones), I would disagree because data integrity and abstraction of data and content doesn’t matter much anymore.