Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > How to add attributte into GetImage() method? View modes: 
User avatar
Member
Member
steven4733-gmail - 1/24/2012 10:44:12 AM
   
How to add attributte into GetImage() method?
I checked the source code of an output page, which uses GetImage() method to display images that uploaded by page editor. If I uploaded an image test.jpg, the source code will be something like this
<img alt="" src="/getattachment/a83b64af-d506-433c-9bda-0db4c8718d78/test.aspx" />


Now I want to add an attribute into the image, e.g "Title". So I want it output like
<img alt="" src="/getattachment/a83b64af-d506-433c-9bda-0db4c8718d78/test.aspx" Title="This is an example title"/>


In this way, my js could use the "Title" attribute. How to add attributes?

User avatar
Kentico Support
Kentico Support
kentico_janh - 1/25/2012 1:42:44 AM
   
RE:How to add attributte into GetImage() method?
Hello,

Could you please specify, how exactly did you upload the image and where? If you mean wysiwyg editor in the CMS Desk, you can double-click on that uploaded image -- the pop-up appears -- and there is a Tooltip property (which is actually a Title property of that image) under the Advanced tab.

Best regards,
Jan Hermann

User avatar
Member
Member
steven4733-gmail - 1/25/2012 8:30:24 AM
   
RE:How to add attributte into GetImage() method?
I don't use wysiwyg editor, I use selector to upload file. Just a file type field in the document type. Is that possible to define an attribute?

User avatar
Kentico Support
Kentico Support
kentico_janh - 1/26/2012 3:07:32 AM
   
RE:How to add attributte into GetImage() method?
Hello,

There is also the CMS.GlobalHelper.MediaHelper.GetImage(ImageParameters) method, in which you can define all following parameters:

Align - Image align.

Alt - Image alternative text.

Behavior - Image behavior.

BorderColor - Image border color.

BorderWidth - Image border width.

Class - Image css class.

Dir - Image direction definition (rtl, ltr).

EditorClientID - Client id of editor for inserting content.

Equals(Object) - Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)

Extension - Image extension.

Finalize() - Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection.
(Inherited from Object.)

GetHashCode() - Serves as a hash function for a particular type.
(Inherited from Object.)

GetType() - Gets the Type of the current instance.
(Inherited from Object.)

Height - Image height.

HSpace - Image horizontal space.

Id - Image Id.

Lang - Image language definition.

Link - Image link destination.

LongDesc - Image long description definition (url).

MemberwiseClone() - Creates a shallow copy of the current Object.
(Inherited from Object.)

MouseOverHeight - Height of the thumbnail image which is displayed when mouse is moved over the image.

MouseOverWidth - Width of the thumbnail image which is displayed when mouse is moved over the image.

SizeToURL - Gets or sets the value which determines whether to append size parameters to URL.

Style - Image inline style.

Target - Image link target (_blank/_self/_parent/_top)

Tooltip - Image tooltip text.

ToString() - Returns a String that represents the current Object.
(Inherited from Object.)

Url - Image source url.

UseMap - Image use map definition.

VSpace - Image vertical space.

Width - Image width.


For more information about this method, please download our Kentico CMS API Reference from the link above:

http://devnet.kentico.com/Documentation.aspx

Best regards,
Jan Hermann

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 1/27/2012 3:33:16 PM
   
RE:How to add attributte into GetImage() method?
You could, alternatively, use the GetFileUrl method in your transformation and write the rest of your image tag yourself. You can also add a field to your document type for the alt text of your image or just use an existing field. This is from the documentation

GetFileUrl(object attachmentGuidColumn)

<%# GetFileUrl("ProductPhoto") %>
• Returns URL of the file specified by the attachment GUID column of the given name.

and here is an example:


<img src="<%#GetFileUrl("ImageFieldName")%>" alt="<%#Eval("AltTextFieldName")%>" />
<!-- You can also add some parameters to set the size of the image like this -->
<img src="<%#GetFileUrl("ImageFieldName")%>?maxsidesize=50" alt="<%#Eval("AltTextFieldName")%>" />