statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
3.89k stars 521 forks source link

Issue with using assets tag with collection when using 'as' #10532

Closed dannyuk1982 closed 2 months ago

dannyuk1982 commented 2 months ago

Bug description

Something weird happens when using an asset tag with :url= syntax when using as= on the collection tag.

How to reproduce

So this code works:

{{ collection from="blog" }}
    {{ asset :url="thumbnail_image" }}
        {{ url }}<br>
    {{ /asset }}
{{ /collection }}

This doesn't (adding in as="posts")

{{ collection from="blog" as="posts" }}
    {{ posts }}
        {{ asset :url="thumbnail_image" }}
            {{ url }}<br>
        {{ /asset }}
    {{ /posts }}
{{ /collection }}

Error: Statamic\Assets\AssetRepository::find(): Argument #1 ($asset) must be of type string, null given

However this does work

{{ collection from="blog" as="posts" }}
    {{ posts }}
        {{ asset url="{thumbnail_image}" }}
            {{ url }}<br>
        {{ /asset }}
    {{ /posts }}
{{ /collection }}

Not a biggie as it works with the url="{foo}", but I guess it should work with the :url="foo"syntax too.

Logs

No response

Environment

Statamic 5.17

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

jasonvarga commented 2 months ago

Weird that it doesn't happen without the as but it might be because one of the entries in the loop doesn't have a thumbnail_image.

dannyuk1982 commented 2 months ago

Yea, there are a couple of don't have thumbnail_image set to anything.