Saturday, February 16, 2008

Accessible variation label menu

This is my little contribution to the improvement of the accessibility in MOSS. I use this user control to show my variations in an accessible manner without tables.

<%@ Control Language="C#" %>
<%@Assembly Name="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
<%@Register TagPrefix="CMS" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.Publishing.WebControls"%> <cms:VariationDataSource id="LabelMenuDataSource" LabelMenuConfiguration="1" Filter="" runat="server"/>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="LabelMenuDataSource" EnableViewState="False">
<ItemTemplate>
<a href="<%# DataBinder.Eval(Container.DataItem, "NavigateUrl") %>">
<%# DataBinder.Eval(Container.DataItem, "DisplayText") %></a>&nbsp;
</ItemTemplate>
</asp:Repeater>

To use it you can replace the content of the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES\VariationsLabelMenu.ascx with the code above. In those cases where there are different publishing portals on the same MOSS installation you can create a new file in the same directory (for example MyCustomVariationsLabelMenu.ascx) and use it in your master page simply changing the register tag.

Original tag:

<%@ Register TagPrefix="PublishingVariations" TagName="VariationsLabelMenu" src="~/_controltemplates/VariationsLabelMenu.ascx" %>

New tag:

<%@ Register TagPrefix="PublishingVariations" TagName="VariationsLabelMenu" src="~/_controltemplates/MyCustomVariationsLabelMenu.ascx" %>

12 comments:

Unknown said...

How can I create my own or customize VariationsLabelMenu.ascx to function like how it is on this multilingual site - http://denny.denish.com/elearnexpo.com/paris/paris_venue.htm. I mean my client don't like the drop down function of the VariationsLabelMenu. They want it simple - Like on the english pages there should be a link 'français' which will link to the corresponding french pages and similarly on the french pages there should be a link 'english' which will link to the corresponding english pages. Please help.

Thanks.
Denny

Àlex said...

Denny,
The example that I have posted makes just what you need. Have you tested it?

Unknown said...

Thank you very much Alex. I just tested the example. And, it is exactly what I was looking for. Thanks a zillion.

Unknown said...

Hi,

I tried this and it seems to work, but I ran into an issue where if I try to view the history on a page and click on a version to view, I get the following error. I don't get it if I put the original VariationsLabelMenu.ascx back. Any ideas what might be going on? This is with MOSS SP1 + latest infrastructure updates.

Thanks!

[NullReferenceException: Object reference not set to an instance of an object.]
Microsoft.SharePoint.Publishing.<>c__DisplayClass29.< GetGroupedPageUrls>b__25() +689
Microsoft.SharePoint.SPSecurity.CodeToRunElevatedWrapper(Object state) +58
Microsoft.SharePoint.<>c__DisplayClass4.< RunWithElevatedPrivileges>b__2() +344
Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) +137
Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param) +331
Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) +81
Microsoft.SharePoint.Publishing.PublishingPage.GetGroupedPageUrls(String siteUrl, String pageUrl, String groupId) +192
Microsoft.SharePoint.Publishing.WebControls.VariationEnumerable.System.Collections.IEnumerable.GetEnumerator() +700
System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +343
System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +53
System.Web.UI.WebControls.Repeater.DataBind() +72
System.Web.UI.WebControls.Repeater.EnsureDataBound() +55
System.Web.UI.WebControls.Repeater.OnPreRender(EventArgs e) +12
System.Web.UI.Control.PreRenderRecursiveInternal() +86
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041

Àlex said...

Ed,
It could be an issue with the security and the variations.

You can check your SharePoint logs or modify the control in order to locate the error.

Anonymous said...

Hi there
Thx. did just what i needed it to do with some tweeks;). Any ideas how we could get the language back localized? eg if they on the Italian site english should be showen as Inglese?
Once again thx.
Ric

Àlex said...

Well,
I like to show the language in the original language, but if you prefer the translated label you can add the code to translate each label before render it.

Anonymous said...

thanks. it was exactly what i needed.

Anonymous said...

Hi Alex,

this one was just wonderfull and right at the time of needing it :)

it works like a charm, but now I'm trying to display ALL the variation languages next to eachother. I'm using the "itemseparator" for showing a | .

I have three languages, Dutch, English and French and we'd love to see all the languages next to eachother, instead of always switching "two" languages at the top (hope you know what I mean :$ ).

Any solution for this?

Regards,

Nesreen said...

Hello,

I have problem with the page history i gives error when ever i use this new varation label look , any Idea??Please help

Anonymous said...

секс голые девочки http://free-3x.com/ училки фото free-3x.com/ онлайн порно секс с малолетками [url=http://free-3x.com/]free-3x.com[/url]

Anonymous said...

Nice to meet you!!!
[URL=http://superjonn.50webs.com/restaurant-week-february-2010.html]restaurant week february 2010[/URL]

 
Online Visitors