Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > How to show image alt value using GetImage method View modes: 
User avatar
Member
Member
gliker-inorbital - 8/23/2011 2:06:53 PM
   
How to show image alt value using GetImage method
Hi guys, is there any way to add alt value to image from the document type field using GetImage method. For example:

<%# GetImage("NewsTeaser", 200, 200, "some alt text") %>


So instead "some alt text" I would like this image to be resized and displayed with alt tag from document type field.

Thanks

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 8/24/2011 2:41:32 AM
   
RE:How to show image alt value using GetImage method
Hi,

for the alt text parameter you can use the EVAL function:

<%# GetImage("NewsTeaser", 200, 200, ValidationHelper.GetString(Eval("fieldName"),"")) %>

Best regards,
Juraj Ondrus

User avatar
Member
Member
gliker-inorbital - 8/24/2011 8:00:03 AM
   
RE:How to show image alt value using GetImage method
Hi Juraj,

I tried your code and I got this error:

[CMSDataProperties.LoadTransformation]: http://server/CMSTransformations/1f7da230-f99f-4c91-a243-9fc2cf8b819c/custom/mediumcontentpreview/default.ascx(208): error CS1501: No overload for method 'GetImage' takes 4 arguments


This is old method I'm trying to replace because images are resized in the browser:
<img src="<%# Eval("mcp_image") %>" width="214px" height="139px" alt="<%# Eval("mcp_title") %>"/>


And I replaced it with:
<%# GetImage("mcp_image", 214, 139, ValidationHelper.GetString(Eval("mcp_title"),"")) %>


Any idea what I'm doing wrong? Thanks.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 8/24/2011 9:54:56 AM
   
RE:How to show image alt value using GetImage method
Hi,

As the error message says, there is no overload with 4 arguments for the GetImage method/function.

You need to use e.g. this overload: GetImage(object attachmentGuidColumn, object maxSideSize, object width, object height, object alt)

And for the last parameter - since it is an object, it might not be necessary to use ValidationHelper to convert it to string. Just Eval("columnName") should be enough.

Best regards,
Juraj Ondrus

User avatar
Member
Member
gliker-inorbital - 8/24/2011 11:25:49 AM
   
RE:How to show image alt value using GetImage method
Thanks Juraj,
Finally I'm not getting an error but now image src property has wrong path. This is code I'm using:
<%# GetImage("mcp_image", 214, 214, 139, Eval("mcp_title")) %>


Path to image should look like this:
<img src="/CorporateSite/media/oht/3By2Ratio/Elgin-interior-03.jpg?width=960&height=640&ext=.jpg" width="214px" height="139px" alt="Some alt text...">


But I'm getting this:
<img alt="Some alt text..." src="/getattachment/00000000-0000-0000-0000-000000000000/EWG---ENG.aspx?maxSideSize=214&width=214&height=139" border="0">


Can you help me with this last hurdle please?

Thanks.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 8/25/2011 2:00:25 AM
   
RE:How to show image alt value using GetImage method
Hi,

What kind of attachments do you use (please see the documentation)?

In the documentation, there you can also find pre-defined web parts for displaying attached images - you can take a look at their transformation and see which functions are used - e.g. the GetImage function will always return URL with the image GUID. You can also use e.g. GetAttachmentUrl function - it is up to you.

Best regards,
Juraj Ondrus

User avatar
Member
Member
gliker-inorbital - 8/25/2011 9:04:07 AM
   
RE:How to show image alt value using GetImage method
Hi Juraj,

Looks like something have been hardcoded and it's overwriting image size setting I have setup in function. This is how image url looks now.

<img alt="Some alt text..." src="/SomeSite/media/images/3By2Ratio/ImageName.jpg?width=960&height=640&ext=.jpg?maxSideSize=214&width=214&height=139" border="0">

Thanks anyway for sticking with me through this. I think it's only up to us now to figure out this.

Have a great day,
Giuliano