2

I've implemented a content type which includes a file field.

articles:
  fields:
    title:
      type: text
    body:
      type: html
    attachment:
      type: file

When I go to output the information in a template I access the file with:

record.attachment

However this only provides me with the path of the file and nothing else.

Question: Is it possible to get the filesize and a human friendly filename from the record object? Or do I have to create a Twig function in an extension to do this?

An alternative? I guess the alternative would be to create a files contenttype with fields for name, size, etc. Then relate this back to my article.

diggersworld
  • 12,770
  • 24
  • 84
  • 119

1 Answers1

1

Personally I'd opt to do this in a twig filter. If you use an image we already have a built in filter do get this information {{imageinfo(fieldname)}} will return an array of information.

Logically a similar function fileinfo could get the necessary info if all you are interested in is the metadata about a file.

If you do want to store additional content information that can't be discerned via a php function then you will need to use the related content type idea.

Ross Riley
  • 826
  • 5
  • 8