Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Media Library Image Alternate Text View modes: 
User avatar
Member
Member
DahlinDev - 7/2/2013 12:08:13 PM
   
Media Library Image Alternate Text
When selecting images from the Media Library there is an Alternate Text field. How can I access this field?

Is there a certain selector I need to use and what method in the transformation would I need to use?

Currently I am using Text type for the field and Media Selection for the control.
I then add an extra field for the Alt Text.

Then in my transformation I use, <%# GetImageByUrl(Eval("MyImage"), 100, 100, 100, Eval("MyAltText")) %>

It would be less confusing for the user if they could just enter the alt on the selection of the image.

User image

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 7/8/2013 7:10:13 PM
   
RE:Media Library Image Alternate Text
Hello,

Unfortunately it's not possible to access this field in the transformation because the content of this field is stored with the document's content. So it is rendered just directly on the page.

Best Regards,
Martin Danko

User avatar
Member
Member
sandor.voordes-tamtam - 7/12/2013 7:28:18 AM
   
RE:Media Library Image Alternate Text
Hi Martin,

Unfortunately though whatever text I fill in, it is not rendered in the alt attribute of the page HTML. It actually renders alt='Voorbeeld' (dutch) for all images rendered through the mentioned media selector.

Sandor

User avatar
Member
Member
sandor.voordes-tamtam - 7/12/2013 7:29:19 AM
   
RE:Media Library Image Alternate Text
Uhm, for carification, I use:

<cms:Media id="MediaElement1" runat="server" URL='<%# Eval<string>("Image") %>' />

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 7/20/2013 8:22:23 PM
   
RE:Media Library Image Alternate Text
Hello Sandor,

Ok, the Alternative text should be used only when you are inserting the media library file directly into the Editable region.

In this case I would recommend you the following solution:
1. Create a custom form control which will be copy of \CMSFormControls\Basic\MediaSelectionControl.ascx (+ .cs file)
with name e.g. MediaImageSelectionControl.ascx

2. Open this control in VS and add a Text field where alternative text will be entered:
<asp:TextBox ID="txtAlt" runat="server" />
<cms:MediaSelector ID="mediaSelector" runat="server" />

3. Make some changes in the code-behind (cs) file to handle alternative text correctly:
at the beginning of your class create a private variable:
    #region "variables"

private string altText = "";

#endregion

modify the Value object:
    public override object Value
{
get
{
return mediaSelector.Value + "|" + txtAlt.Text;
}
set
{
string myValue = ValidationHelper.GetString(value, null);

mediaSelector.Value = myValue.Split('|')[0];
altText = myValue.Split('|')[1];
}
}

at the beginning of Page_Load method assign this variable:
    protected void Page_Load(object sender, EventArgs e)
{

txtAlt.Text = altText;
...

You can also modify a dialog to accept only images as media files for this selector:
mediaConfig.SelectableContent = SelectableContentEnum.OnlyImages;

4. In the CMS Site Manager -> Development -> Form controls , create a new Form Control -> Media Image Selection

5. Add new field to your document type with this new control, the alternative text will be then parsed automatically and you will be able to work with this field

Best Regards,
Martin Danko