attachment
The attachment object is returned when an attribute of a media field is called. E.g. {{ post.featured_image }}
(when featured_image is a media field) returns an attachment object.
attachment.crop
Returns the crop values of the attachment if it’s an image. The values are:left, top, width, height
. By default the left and top are set to 0, and width and height to 100% of the image size, i.e. no crop. The attachment’s crop values can be changed by enabling inline crop in the img_tag
filter.
attachment.src
Returns the original url of the attachment.
attachment.meta
Returns an object with the attachment’s meta information, i.e. file mime type, file size, image dimensions if attachment is an image, etc.
The meta object has the following attributes for all files:
mime_type
file_size
ext
(file extension)alt
(changeable when editing the file in the media library)title
(changeable when editing the file in the media library)
When the attachment is an image, it has the following attributes as well:
format
(image type: jpg, png, etc)width
height
aspect_ratio
landscape
(returns true when image is in landscape)
attachment.file_name
Returns the file’s name, the part of the src
url that represents the file.
attachment.content
Returns the file’s content, but only if the file contains plain text and is readable.
Files that are considered plain text and readable are:
- Plain text files, like TXT, or code files like JSON, HTML, CSV, etc.
- SVG image files