New: Learn Statamic on Laracasts!

We've retired the forum in favor of GitHub Discussions.

New conversations can be started on GitHub. Existing conversations will remain for a while longer.

Head over to GitHub →

How to Convert an Asset URL to an Asset Object for a Single Image on a Partial?

Ed Talmadge April 10, 2019 by Ed Talmadge

I have a partial that is used to display an image:

{{ hero_content }}
  <img src="{{ value }}" alt="{{ alt }}" />
{{ /hero_content }}

And, I have a fieldset assigned to the image container:

    display: Main
        type: text
        display: Alt
taxonomies: true
title: 'Standard Image'

With the above setup, the alt attribute value in the html output is blank.

I saw in the documentation that it's possible to create an Asset object and loop through all assets (and their values, such as the alt value) using the below code.

{{ assets:photos }}
  <img src="{{ url }}" alt="{{ alt }}" />
{{ /assets:photos }}

But, I would like to add an alt attribute to a single image.

Is there a way to do that?

Answered by Erin Dalzell!
>>>>>>> Answered <<<<<<<
4 Replies