file Object

File download block for use within content template displays.

Attributes

Attribute Required Description
title Yes string Title of file.
description No number Description of file.
url Yes string URL where original file is stored/downloadable.
extension Yes string Extension of file. For example, pdf.
url_slug Yes string File name minus extension.
content_type Yes string MIME type of file. For example, application/pdf.
file_size Yes number Size of file in bytes.
keywords No string List of keywords to describe file.
downloadable? Yes boolean Whether or not the content author specified to include a download link to this file.
audio? Yes boolean Whether or not this is an audio file. If so, this file object will include additional attributes provided by the audio block object.
image? Yes boolean Whether or not this is an image file. If so, this file object will include additional attributes provided by the image block object.
pdf? Yes boolean Whether or not this is a pdf file. If so, this file object will include additional attributes provided by the pdf block object.
video? Yes boolean Whether or not this is a video file. If so, this file object will include additional attributes provided by the video block object.
published_at No date Timestamp of when file was first published.
created_at Yes date Timestamp of when file was created.
updated_at Yes date Timestamp of when file was last updated.
id Yes number ID of file.

Category

Block Objects

Description

The file block object defines a container for any kind of file. This object will be used in a content template when the author needs to upload a file of any type: audio, image, pdf, video, or any other type.

Attributes provided by the file object can determine whether or not to embed the content into the page (if the type allows), provide a link to download the original file, or both.

Within your content templates’ displays, you would reference the block’s var_name containing the file data. (It won’t necessarily be named file but rather the name that you define in the content_templates.json file.)

Here is an example of using various file attributes to decide what to display for the file within a content template display:

      {% comment %}
        Embed file if content author marks this as
        embeddable.
      
        In this ficticious example, we're including files in the
        includes/ folder for each type of embeddable file. You
        would need to code your own.
      {% endcomment %}
      {% if file.embeddable? %}
        {% if file.audio? %}
          {% include 'audio_embed' %}
        {% elsif file.image? %}
          {% include 'image_embed' %}
        {% elsif file.pdf? %}
          {% include 'pdf_embed' %}
        {% elsif file.video? %}
          {% include 'video_embed' %}
        {% endif %}
      {% endif %}
      
      {% comment %}
        Link to file download if content author marks this as
        downloadable.
      {% endcomment %}
      {% if file.downloadable? %}
        <p>
          <a href="{{ file.url }}">Download {{ file.title }}</a>
        </p>
      {% endif %}