Add text data on drag and drop from file

On panel, user can drap and drop file from files list to create file’ KirbyTag.
Currently only url field is set on markdown editor, wether others fields exists:

(file: file__url)

My need is to display a name instead of the filename. This name is the one contained in textfield.

(file: file__url text: my__name)

So, for example let’s consider a file with the following attributes:

  • URL : fileURL
  • filename : elvispresley.pdf
  • text: Elvis is alive!

After drag and drop, here is the KirbyTag displayed on markdown editor:

(file: fileURL/elvispresley.pdf text: Elvis is alive!)

See panel | Kirby CMS

Hi! Thank you for your answer that helped a lot. Unfortunately I still don’t know which field need to be used to carry this replacement data as there are many options to follow. Is there an existing field already dedicated to this purpose? Is there some kind of alt field?

Since you have access to the $file object, you can use any meta data:

   'panel' => [
        'kirbytext' => [
            'fileDragText' => function(Kirby\Cms\File $file, $url) {
                if($file->type() === 'image') {
                    return sprintf('(image: %s text: %s)', $url, $file->title()->or('Some fallback text')) ;

                if($file->type() === 'document') {
                    return sprintf('(file: %s text: %s)', $url, $file->description()->or($file->name()));

                return null;


OK, thank you for the help! Retrieving the wanted field is now ok. But not link is created for the file! :frowning: The HTML code produced contains is not a link.

File’s URL as dropped in the Markdown field is the one on media folder:
media/pages.... It is OK as I copied/pasted it on a browser and file showned.

Replacing it with the relative link is OK. So the $file->url() code in your example does not work.

Yes, should’ve been $url, sorry.

1 Like

Thank you very much.