Adding Alt Tags to GetImage("NewsTeaser")

L Younkins asked on September 15, 2020 20:52

Using Kentico 10. Developed by former partner who didn't add alt tags to news article teaser images.

<%# IfEmpty(Eval("NewsTeaser"), GetImageByUrl("/media/Images/Home2018/NewsDefault.jpg"), GetImage("NewsTeaser")) %>
<%# Eval("NewsSummary") %>

Recent Answers


Juraj Ondrus answered on September 16, 2020 07:13

What about using one of the overloads with the alternate text parameter as shown in the documentation? You would need to specify the dimensions though...

<%# GetImage("NewsTeaser", 200, 200, 100, "image alternate text") %>

0 votesVote for this answer Mark as a Correct answer

L Younkins answered on September 16, 2020 15:13

<%# IfEmpty(Eval("NewsTeaser"), GetImageByUrl("/media/Images/Home2018/NewsDefault.jpg"), GetImage("NewsTeaser","AltImage")) %> <%# Eval("NewsTitle") %> <%# Eval("NewsSummary") %> I tried adding this, and it doesn't seem to work. The AltImage is a new field that I created, which does show up on the news thumbnail upload, but doesnt show up when you look at the source code.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on September 16, 2020 16:01

The parameter for alternate image is the 5th one, as mentioned, you need to define the dimension parameters too:
<%# GetImage("NewsTeaser", 200, 200, 100, "image alternate text") %>
And if you want to use some field, you may need to use Eval< string >("FieldName")

0 votesVote for this answer Mark as a Correct answer

L Younkins answered on September 16, 2020 16:42

As in:

<%# IfEmpty(Eval("NewsTeaser"), GetImageByUrl("/media/Images/Home2018/NewsDefault.jpg"), GetImage("NewsTeaser") Eval("AltImage")) %> <%# Eval("NewsTitle") %> <%# Eval("NewsSummary") %>

Does it go in the main parenthesis as above or a separate parenthesis, after the ("NewsTeaser"))?

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on September 17, 2020 05:38

The GetImage method, if you want to use the alt text property has 5 parameters, so you need to define them all, separated by colon:

<%# GetImage("NewsTeaser", null, null, null, < AltTextField >) %> or,

<%# GetImage("NewsTeaser", null, null, null, Eval< string >("AltTextField")) %>

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.