Custom Methods in Panel

I want to check wether an image has some alt text and show this in the panel (txt or info) of a files field.

So to show the alt field text I can use:

info: {{ file.alt }}

But if it is empty I would like to show a warning text instead of nothing.

I presume this would require an external method but I’m not sure if it should be a custom field or file method?

So I tried using a small plugin called file-methods with an index.php of:

Kirby::plugin('sfi/file-methods', [
  'fileMethods' => [

    'alt-warn' => function () {
      /* Just trying to return some stuff here*/
      return $this->file()->filename();

But using the below does not work.
info: {{ file.alt -warn}}

I’m obviously missing something here and would appreciate any pointers.

You cannot use dashes in function names! Use camelCase or under_score

Instead of a custom method, I think you could also use or()

info: {{ file.alt.or('Missing alt text') }}

Thanks pixelijn, I agree for this particular example you solution is good. But supposed I wanted to do some something more complicated with an image files parameters like size or ratio and show that in the panel, which type of method would I need?

p.s. I did change the function name in my example above to camelCase but no luck?

Should be $this->filename() because $this already refers to the file.

Thanks pixelijn, sometimes I can’t see the wood for the trees :slightly_smiling_face: