Assets Field

Allows for the selection of assets

Options#

  • Asset Group – Restrict the selection of assets to a specific asset group.

  • Types – Restrict the selection of assets to specific types.

    • Access

    • Audio

    • Compressed

    • CSV

    • Excel

    • Flash

    • Gimp

    • Html

    • Illustrator

    • Image

    • Javascript

    • Json

    • Pdf

    • Photoshop

    • Php

    • Powerpoint

    • SQL

    • Text

    • Video

    • Word

    • Xml

  • Custom Label - A custom label users will see when adding assets to the field.Default is "Add Asset", the word "Asset" is the label that will be replaced with your custom label.

  • Limit - Maximum number of assets that can be uploaded to this field.

Use#

When a user clicks the “Add Asset” or “Add {your custom label}” button a modal will popup allowing for the selection of an asset. If the restrict selection was set to a specific asset group then only assets in the asset group will be made available for selection. Further more, if the selection was restricted to specific types of files eg “Image” then only files of that type will be selectable.

An asset is then selected by clicking on it. The user will also have the option of uploading a new asset or searching for specific assets.

If the field has been set to required then the entry will not be update-able until at least one asset has been selected.

If the field has a limit set, then only that number of assets will be allowed to be selected. Once the limit has been reached the button to add more assets will disappear. If the limit is modified at a later date, and the field contains more than the new limit, an error will be shown notifying the user that they must remove assets from the field to match the new limit.

Template Use#

Access your asset fields via the handle you set for the field. Each asset field provides an array accessed via assetFieldHandle which contains the assets stored in the field, in the order set by the content creators.

{% set assets = entry.yourFieldHandle.assetFieldHandle %}

Each asset in the assetFieldHandle array is an instance of a \Enact\template\wrapper\Asset, which provides properties and methods for interfacing with each asset via your twig templates.

Examples#

The loop

{% for asset in entry.yourFieldHandle.assetFieldHandle %}

    {{ asset.getImgHtml }}

{% endfor %}

Check if the field contains assets

{% if entry.yourFieldHandle.assetFieldHandle | length %}

    {{ entry.yourFieldHandle.assetFieldHandle[0].title }}

{% endif %}

// or test the 0 index of the array

{% if entry.yourFieldHandle.assetFieldHandle[0] %}

    {{ entry.yourFieldHandle.assetFieldHandle[0].getLinkHtml }}

{% endif %}

Another basic usage example

{% set asset = entry.yourFieldHandle.assetFieldHandle[0] %}

{% if asset %}

    <a href='{{ asset.url }}'>{{ asset.title }} - {{ asset.fileSize }}</a>

{% endif %}