Skip to main content
4 votes
Accepted

How do you insert the site name into a default asset path?

Try using {site.handle} instead of {{currentSite.handle}} and it should work ok.
revlis's user avatar
  • 383
4 votes
Accepted

Eager-Loading Assets in Matrix

The reason this doesn't work is because .type('image') won't work with eager loading. Eager loading removes the ability to use ElementCriteriaModel methods. From the docs: When the assets aren’t ...
Alex Roper's user avatar
  • 2,642
3 votes
Accepted

Viewing Assets (PDFs) associated with an entry directly from that entry screen

I'm guessing you may have found an answer to this, but have you seen the download assets plugin? It puts a download button next to every asset on an edit page that links to the asset's url.
dmatthams's user avatar
  • 2,502
3 votes
Accepted

Asset dynamic subfolder for User Matrix

You should be using {{currentUser.id}} instead of {currentUser.id} The difference is that double curly brace syntax works on the global scope, while single curly brace syntax tries to resolve itself ...
Andris Sevcenko's user avatar
2 votes

How to get second asset?

In Craft 3 this should be: {% if entry.images | length > 1 %} {% set secondImage = entry.images.1 %} {% endif %}
Document Services's user avatar
2 votes
Accepted

Send currentUser id along with uploaded asset

Thanks for the assist. Just updated my Craft and all sorted.
Ian Ebden's user avatar
  • 894
2 votes
Accepted

Outputting SVG from an asset field inside a matrix field with svg()

Ok, think I know what's wrong – you want to select the first asset, but not its url. E.g. {{ svg(callout.icon.one()) }}
dmatthams's user avatar
  • 2,502
2 votes
Accepted

Front End Entry Form - File/asset field not saving when ajax submitted

Finally found the answer after much time spent on it. The $(this).serialize() loses the file input - and can't submit. Updated ajax submit to $.ajax({ type: 'POST', url: url, data: new ...
mmc501's user avatar
  • 1,789
2 votes
Accepted

Import local image with FeedMe assumes wrong folderId

So, I found the problem / solution myself: I have 2 file volumes in my Craft installation (documents, images) The asset field I am trying to fill via FeedMe is in its configuration limited to the &...
Matthias Redl-Mann's user avatar
2 votes
Accepted

which Sources of asset field are checked

You can get all available sources with field.getSourceOptions() Which returns you an array of all sources, no matter if they are selected or not (just to get the ids and such) and with field....
Robin Schambach's user avatar
2 votes
Accepted

Deleting one or all Assets from a fieldusing a front end form

Assuming you are on a front end entry form editing an entry, there are a few steps to this. First get all assets a user can choose from: {% set allImages = myAssetQuery.all() %} Next, get the ids of ...
Oli's user avatar
  • 7,515
2 votes

Asset upload hangs when uploading to asset field in entry

Rather than throwing an exception when the filesize is too large, you should be adding a validation error, which should be handled correctly. use craft\base\Model; use craft\elements\Asset; use craft\...
Brandon Kelly's user avatar
2 votes

Get Entry Slug from specific Locale

This might not be a full blown solution but given the current entry, you can get the corresponding entry of another site by using {% set otherLocaleEntry = craft.entries.siteId(lang.id).id(entry.id)....
MisterMike's user avatar
2 votes
Accepted

Get Entry Slug from specific Locale

Thanks to MisterMike's answer I was able to get what I want. My asset location path is now set to {{craft.entries.siteId(1).id(id).one().slug}}. The siteId 1 is the ID of the site from which i want to ...
Sandro's user avatar
  • 53
2 votes
Accepted

Assets dynamic location functions of site

There are two issues with your code: You aren't able to reference entry in the field. This section in the docs describes the rules around using Twig in the Entry title field, and the same rules apply ...
Jalen Davenport's user avatar
  • 3,045
1 vote
Accepted

Upload asset via API - Asset saved under root folder

I am not sure yet what caused the issue, but it is probably somehow related to the fact that I also created the volume programmatically. At any rate, using an absolute path during volume creation ...
Matanya's user avatar
  • 492
1 vote

Split Assets volume into two

You may need to write some kind of utility code to assist you in this task. I would use a console command for this that: loops over the entries in the "Staff Articles" section loops over ...
nstCactus's user avatar
  • 1,149
1 vote
Accepted

How do you call an asset field from an entry Craft CMS 3?

The documentation on this is a bit scattered about, it took me a while to get the whole picture as well. You need multiple pieces of information: The documentation on querying assets only mentions ...
MoritzLost's user avatar
  • 11.9k
1 vote
Accepted

Feed Me and Assets Field - Mapping Trouble

1.) Have you set the feed to update existing entries? 2.) Try to url-encode the URL in the JSON, it contains special chars like spaces.
Matthias Redl-Mann's user avatar
1 vote

Asset volumes with dynamic subfolder

For a field outside the Matrix, you can use {username} and for the one in the Matrix, use {owner.username} - see docs You might need to run Utilities → Asset Indexes.
Oli's user avatar
  • 7,515
1 vote

Outputting image assets with flickity

If I understand the question properly, this should do it for you: {% if entry.gallery|length %} <div class="main-carousel"> {% for image in entry.gallery.all() %} <div class="...
Oli's user avatar
  • 7,515
1 vote

How to work getFieldValue for assets

I have solved it by myself. $asset = $user->getFieldValue(FIELDHANDLE)->one(); $user->setFieldValues([ 'FIELDHANDLE' => $asset->filename ]);
Kota.M's user avatar
  • 423
1 vote

Importing assets with Feed Me using Element Exporter data

I don't know if you're still facing this issue but it's something I'm working on right now! Basically my solution was to create a short program to parse through the Element Exporter json and to change ...
Jessica Zalzman's user avatar
1 vote

Dynamic Asset Sub Folder Paths based on section and. if/else or turnery operators

So this was a simple fix and not to use {% %} tags but instead to use {{ }} tags. Changing the above logic in the subdirectories filed like so seems to have resolved the issue. {{ section == 'Company'...
Terry Upton's user avatar
  • 1,894
1 vote

Feed Me - syncing asset fields

Of course shortly after posting this I got it working. Created a feed and used the filename as the unique identifier and voila imported redactor content to images for 2000+ images.
CreateSean's user avatar
  • 1,983
1 vote
Accepted

Merging Assets Fields

From Twig, this seems like a decent solution. Could possibly be streamlined a bit if you wanted to do it from PHP, but as long as you're not dealing with large amounts of images, it's probably not ...
Brad Bell's user avatar
  • 67.6k
1 vote

Select Transform Feature with Asset Field

Asset fields require a transform to be set manually in the template or can be Created in the dashboard and the transform name used in the template. {% set thumb = { mode: 'crop', width: 100, ...
Chattervast's user avatar
1 vote
Accepted

How to get second asset?

Image assets are returned in an array. Let's say you have an assets field with the handle of images. You can just use bracket notation to get the second item in the array using: entry.images[1]. So if ...
Tim Knight's user avatar
  • 1,022
1 vote
Accepted

Asset Field: Select a folder instead of all images

You can create a new field with these functions. Note: this is a very basic example, you would usually want to do this with a template but I don't have much time class FolderAssetField extends Field {...
Robin Schambach's user avatar
1 vote
Accepted

How to return asset from custom user field

You have to make sure you enabled the option Assets in this volume have public urls in your volume settings at /admin/settings/assets/volumes/. This checkbox is disabled by default thus your getUrl() ...
Robin Schambach's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible