Skip to content

Commit

Permalink
Support aliasing within the glide tag directly
Browse files Browse the repository at this point in the history
This makes the following type of Blade template "Just Work":

```blade
<s:glide :src="$multiple_assets" width="600" as="assets">
  @foreach ($assets as $asset)
    {{ $asset['url'] }}
  @Endforeach
</s:glide>
```
  • Loading branch information
JohnathonKoster committed Oct 19, 2024
1 parent c495de3 commit 213f865
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Tags/Glide.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function dataUri()
*
* Generates the image and makes variables available within the pair.
*
* @return string
* @return string|array
*/
public function generate($items = null)
{
Expand All @@ -131,7 +131,11 @@ public function generate($items = null)

$items = is_iterable($items) ? collect($items) : collect([$items]);

return $items->map(function ($item) {
if ($alias = $this->params->get('as')) {
unset($this->params['as']);
}

$items = $items->map(function ($item) {
try {
$data = ['url' => $this->generateGlideUrl($item)];

Expand All @@ -150,6 +154,14 @@ public function generate($items = null)
\Log::error($e->getMessage());
}
})->filter()->all();

if ($alias) {
return [
$alias => $items,
];
}

return $items;
}

/**
Expand Down

0 comments on commit 213f865

Please sign in to comment.