Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scope attribute cast data to array #11259

Open
dadaxr opened this issue Dec 16, 2024 · 0 comments
Open

scope attribute cast data to array #11259

dadaxr opened this issue Dec 16, 2024 · 0 comments

Comments

@dadaxr
Copy link
Contributor

dadaxr commented Dec 16, 2024

Bug description

Iterating over an "assets" field (multiple assets) using a "scope" attribute, cast the image data to an array.

If we want to use glide tags we have to be careful because glide does support "Asset entry" or "relative url" as it's "src" param (see #https://statamic.dev/tags/glide#asset) , but not an array :

{{ images scope="img" }}
  {{# here "img" is an array, so we cannot do that :  #}}
  {{ glide :src="img" w="100" h="100" }} 
{{ /images }}

we can of course use "img.url" instead of "img", but it's frequent to use a dedicated "partial" to manage glide manipulation, and passing it only one image param, so we need to be carefull of the type of data. And it happens, we want to use glide with "public url" and not an asset field, so using the "img.url" notation does not always work...

For instance, if we have an "asset" field (containing only one asset), we can do that :

  {{ glide :src="img" w="100" h="100" }}  
{# it works because img is an asset field supprted by glide, it would also work if img would be a public url string #} 

So I guess my question is : when iterating over an "assets field" (multiple assets) using a "scope" param, do we need to cast each asset to an array ? Can't we just receive the "asset entry" directly ?

Also casting each variable to an array, does also trigger full augmentation, which might cause some performance issues... I guess we could be clever and detect the type of data being iterated over, to cast it to the more appropriate datatype (asset entry, entry, or whatever, and falling back to an array when needed)

What do you think ?

How to reproduce

just read the bellow examples

Logs

No response

Environment

Environment
Laravel Version: 10.48.22
PHP Version: 8.2.23
Composer Version: 1.10.27
Environment: prod
Debug Mode: OFF
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: stack / daily
Mail: smtp
Queue: sync
Session: file

Statamic
Addons: 0
Sites: 1
Stache Watcher: Disabled
Static Caching: custom
Version: 5.38.0 PRO

Statamic Addons

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants