site/blueprints/fields/link.yml
type : group
fields :
link :
label : Link-Typ
type : select
width : 1/3
options :
int : Interner Link
ext : Externer Link
info :
width : 2/3
when :
link : " "
label : Kein Link
text : Bitte wählen Sie einen Link-Typ
int :
label : Interner Link
type : pages
multiple : false
width : 2/3
when :
link : int
ext :
label : Externer Link
type : url
width : 2/3
when :
link : ext
site/blueprints/pages/link.yml
title : Link
fields :
link : fields/link
<?php go ($ page ->link ()->toHref ()) ?>
site/plugins/methods/index.php
<?php
Kirby::plugin ('my/methods ' , [
'fieldMethods ' => [
'toHref ' => function ($ field ) {
$ type = $ field ->value ();
if ($ type == "int " AND $ linkPage = $ field ->parent ()->int ()->toPage ()) {
return $ linkPage ->url ();
}
if ($ type == "ext " ) {
return $ field ->parent ()->ext ()->value ();
}
}
]
]);
Optional: site/models/link.php
<?php
class LinkPage extends Page {
public function url ($ options = null ): string {
$ type = $ this ->link ()->value ();
if ($ type == "int " AND $ linkPage = $ this ->int ()->toPage ()) {
return $ linkPage ->url ();
}
if ($ type == "ext " ) {
return $ this ->ext ()->value ();
}
}
}