At the bottom of this page there is a reference to a .GetPropertyValue("alt") on a media picker object. Where does one input the alt text associated with that "alt" attribute?
By default, the Media item doesn't have an alt field. So what you'd need to do is, assuming you have access to the full back office of your Umbraco site, is find the "Media Types" entry. I believe it is in the Settings section.
Under Media types you should find the Image media type.
This is very similar to a document type in that you can add additional properties to it so the first step is to add a property called Alt (or Alt Description, or whatever you would like to call it).
In most situations, I would add this as a Text String property type.
Once you've added that, you can then start thinking about adding Alt Descriptions to your media items.
This is done by going to the Media section of the website and finding the images in there that you want to add Alt text to. Browse to the image in the back office to the point where you can see the uploaded file and all the properties. This is where you'd now see your new Alt field. Add text here and then, your .GetPropertyValue("alt") should work. (Assuming the alias of your property is "alt", if it isn't, change it to be the correct alias.
@Nik that's the direction, I was headed before I saw that .GetPropertyValue("alt") in the documentation. So, I already added the alt attribute to my image media type, and I get where I input that data. What i'm struggling with on that option is how to access my alt text in Razor.
This isn't working...
var heroInsetAlt = Umbraco.TypedMedia(Model.Content.GetPropertyValue<int>("homeHeroInsetImage")).GetPropertyValue("umbracoAltText");
If you break your alt text retrieval down can you check what you are getting out of "homeHeroInsetImage"
So do this:
var imageId = Model.Content.GetPropertValue<int>("homeHeroInsetImage");
var image = Umbraco.TypedMedia(imageId);
var imageAlt = image.GetPropertyValue("umbracoAltText");
Then you can check each line to see what you are getting back. I suspect that either the imageId could be 0, or the Cache isn't updated with your alt text value on the media item you think you are retrieving.
Alt Text on Media Picker Image
At the bottom of this page there is a reference to a
.GetPropertyValue("alt")
on a media picker object. Where does one input the alt text associated with that "alt" attribute?Hi Bh,
By default, the Media item doesn't have an alt field. So what you'd need to do is, assuming you have access to the full back office of your Umbraco site, is find the "Media Types" entry. I believe it is in the Settings section. Under Media types you should find the Image media type.
This is very similar to a document type in that you can add additional properties to it so the first step is to add a property called Alt (or Alt Description, or whatever you would like to call it).
In most situations, I would add this as a Text String property type.
Once you've added that, you can then start thinking about adding Alt Descriptions to your media items.
This is done by going to the Media section of the website and finding the images in there that you want to add Alt text to. Browse to the image in the back office to the point where you can see the uploaded file and all the properties. This is where you'd now see your new Alt field. Add text here and then, your .GetPropertyValue("alt") should work. (Assuming the alias of your property is "alt", if it isn't, change it to be the correct alias.
Hope that helps :-)
Nik
@Nik that's the direction, I was headed before I saw that
.GetPropertyValue("alt")
in the documentation. So, I already added the alt attribute to my image media type, and I get where I input that data. What i'm struggling with on that option is how to access my alt text in Razor.This isn't working...
Any suggestions?
Hi BH,
Can you show what your Image Media Type looks like?
Nik
Okay, so that all looks right to me.
If you break your alt text retrieval down can you check what you are getting out of "homeHeroInsetImage"
So do this:
Then you can check each line to see what you are getting back. I suspect that either the imageId could be 0, or the Cache isn't updated with your alt text value on the media item you think you are retrieving.
That's where I would look next :-)
Nik
@Nik I get the image id
Update my original way actually worked as written:
I didn't apply the
@heroInsetAlt
to the correct img tag (i put it on one image and was looking on a different image).Thanks for your help @Nik. You pointed me in the right direction to find my error. Many thanks!
is working on a reply...