4

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 eager-loaded, entry.assetsField gives you an ElementCriteriaModel that is preconfigured to return the related assets once they’re requested (e.g. when first() is ...


3

Try using {site.handle} instead of {{currentSite.handle}} and it should work ok.


3

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.


3

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 on the current element. Relevant documentation.


2

In Craft 3 this should be: {% if entry.images | length > 1 %} {% set secondImage = entry.images.1 %} {% endif %}


2

Thanks for the assist. Just updated my Craft and all sorted.


2

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


2

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 FormData(this) , dataType : 'json', // changing data type to json processData: false, contentType: false, success: function (response) { // ...


2

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\events\DefineRulesEvent; use craft\helpers\ArrayHelper; use yii\base\Event; Event::on( Asset::class, Model::EVENT_DEFINE_RULES, function(...


2

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 already chosen assets: {% set alreadyChosenImages = entry.businessStandardImages.ids() %} Loop over all images, check the ones already selected: {% for image ...


2

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.sources you'll receive an array if you selected several sources or a string (*) if all are selected.


1

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 the assets selected in the "Staff Photos" field change their volume and folderId save the assets This may not be the best solution but should work.


1

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 craft.assets() as a way to query entries, which you would use to query assets independently of an entry. Meanwhile, you can find the documentation on how to query ...


1

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.


1

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 "images" file volume, but the default location for uploads is (erroneously) configured in the documents share. In this case, FeedMe is determining the ...


1

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.


1

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="carousel-cell"> <img src="{{ image.url }}" alt="{{ image.title }}" /> </div> {% endfor %} </div> {% endif %}


1

I have solved it by myself. $asset = $user->getFieldValue(FIELDHANDLE)->one(); $user->setFieldValues([ 'FIELDHANDLE' => $asset->filename ]);


1

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 anything that was an Asset ID to that asset's url (which Feed Me accepts). public function modifyExport(array $element): array { $result = []; ...


1

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' ? slug : company.one|kebab }}/{section|kebab}


1

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.


1

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 worth it.


1

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, height: 100, quality: 75, position: 'top-center' } %} <img src="{{ asset.getUrl(thumb) }}">


1

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 you wanted to return the URL you could just do: {{ entry.images[1].url }}


1

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 { // Static Methods // ========================================================================= public $folderId; /** * Returns the ...


1

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() function will always return an empty string/null.


1

Of course, just create a new asset source (settings > volumes > new volume) then in your image field select 'Restrict uploads to a single folder' in your field and then select the asset source you just created.


1

With the new hints from Andrew (thanks!), I found a good workaround for me based on this answer: https://craftcms.stackexchange.com/a/21205/8348 Installing the following plugin: https://github.com/aelvan/Imager-Craft The updated Frontend Snippet is the following: {% for entry in latestArticles %} {% set asset = entry.featuredImage.one() %} ...


1

You can assign an image to as many entries as you like; what's happening is for some reason, Craft appears to be unable to generate the appropriate image transform. It's very likely some kind of local dev environment setup issue. For whatever reason, it's unable to access the AssetsController to generate the transformed image on the frontend, as seen in ...


1

Im hesitant to say that this is by design because iam not entirely sure what you mean. Instead i'll explain something i think is comparible that happend to us. We have an entry channel with entries which act as the companies of users on the website. When we saved a company profile in Dutch, fields such as the description or company info would not pull across....


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