Accessing the alt attribute of an asset within Blade #6239
-
I feel like this should be pretty straightforward, but I'm struggling. I'm just trying to output the alt attribute of an asset which is linked to via a blog post (in a collection). I'm using Blade instead of Antlers, which is where the complication comes in. Here's my code: @foreach(Statamic::tag('collection:blog')->sort('date:asc')->limit(4) as $article)
<li>
<div class="space-y-4">
<div class="aspect-w-3 aspect-h-2">
<img class="object-cover shadow-lg rounded-lg" src="{{ $article->feature_image->url() }}" alt="{{ $article->feature_image->alt() }}" />
</div>
<div class="text-lg leading-6 font-medium space-y-1">
<h3>{{ $article->title }}</h3>
<p class="text-indigo-600">{{ $article->category->label() }}</p>
</div>
<div class="text-lg">
<p class="text-gray-500">{{ Statamic::modify($article->content)->stripTags()->safeTruncate(200,'...') }}</p>
</div>
<div class="mt-6">
<a href="{{ $article->url() }}" class="w-full flex justify-center items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50">
Read Full Article
</a>
</div>
</div>
</li>
@endforeach I just can't figure out to get the alt information. As you can see from the code above, currently I'm trying Also, unimportant side note: I'm struggling with the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey @ARCHES-Academy, use Regarding the |
Beta Was this translation helpful? Give feedback.
-
Pass in the parameters as an array. Then it works as expected.
|
Beta Was this translation helpful? Give feedback.
Hey @ARCHES-Academy,
use
$article->feature_image->alt
instead of$article->feature_image->alt()
. Just tried it and works fine 👍Regarding the
safe_truncate
modifier and using it in Blade. The syntax should be correct. Looks like a bug? Will open an issue for it.