Repetitive sublayout - How can I make it unique - to meet ADA requirements

43 Views Asked by At

I have a search box that is loaded twice - once for desktop and once for mobile.

Device determines which is displayed. However, due to ADA, the labeling needs to be unique.

Is there a way to call the sublayout and generate unique tag for each of the html elements to use?

Or, is there a way to generate a tag within the sublayout to ensure the tags are unique.


<div id="desktop">
<sc:Sublayout Path="~/site/sublayouts/Shared/QuickSearch.ascx" runat="server" />
</div>
<div id="mobile-search" class="hidden">
<sc:Sublayout Path="~/site/sublayouts/Shared/QuickSearch.ascx" runat="server" />
</div>

----------- within the layout

<div class="searchtool">
<img src="/includes/images/search.png" alt="Search" style="float:left"/>
<div style="float:left">
<fieldset class="search"  aria-labelledby="Name">

The alt and aria-labelledby tags need to be unique.

Thanks

2

There are 2 best solutions below

0
Chip On BEST ANSWER

I ended up duplicating the sub-layout section - with a new name and changing all the tag elements to reflect different names.

0
Jaybird On

Just an idea, pass the device as a parameter and make the label e.g. "search-desktop" or "search-mobile".

See here for details - http://imjo.hn/2012/02/23/passing-properties-into-sitecore-sublayouts/

<sc:Sublayout Path="~/site/sublayouts/Shared/QuickSearch.ascx" runat="server" 
 Parameters="device=mobile" />

<img src="/includes/images/search.png" alt="Search-<%=GetParameter("device") %>" style="float:left"/>

Here's the helper functions mentioned in that article.

private NameValueCollection _ParameterCollection;
public NameValueCollection ParameterCollection 
{ 
    get
    {
        if (_ParameterCollection == null)
        {
            _ParameterCollection = new NameValueCollection();
            string[] parameters = (Parent as Sublayout).Parameters.Split('&');
            string[] pair;
            foreach (string paramPair in parameters)
            {
                pair = paramPair.Split('=');
                _ParameterCollection.Add(pair[0], pair[1]);
            }
        }
        return _ParameterCollection;
    } 
}

public string GetParameter(string key)
{
    string value = String.Empty;
    string parameterValue = ParameterCollection.Get(key);
    if (parameterValue != null)
    {
        value = parameterValue;
    }
    return value;
}