Developer forum

Forum » Swift » Publications - Language selector

Publications - Language selector

Ferri Halfhide
Reply

Hi Guys,

I’ve set up publications with a language selector, but I have a question regarding the behavior of that selector.

At the moment, the language selector shows all available languages.

What I would like instead is to
only show the languages that are active for the website.

I know that the logic for rendering the language selector is handled in the following template:

  • /Files/Templates/Designs/Swift/Paragraph/Swift_ProductDownloadPublication.cshtml

Could someone give me some advice or guidance on how to adjust this logic so that, the language selector for publications only displays the active languages of the current website, matching the same language list that is used by the website’s main language selector?

 

Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Something like this:

<select name="RequestLanguageID" class="form-select" aria-label="@Translate("Language")">
    @{
        var master = Pageview.Area.IsMaster ? Pageview.Area : Pageview.Area.MasterArea;
        HashSet<string> activeCultures = master?.Languages?.Where(a => a.Active).Select(area => area.Culture).ToHashSet() ?? new HashSet<string>();
        activeCultures.Add(master?.Culture ?? "NA");

        var selected = string.Empty;
        foreach (var language in ecomLanguages)
        {
            if (language.LanguageId.Equals(areaEcomLanguageId, StringComparison.OrdinalIgnoreCase) && activeCultures.Contains(language.Culture ?? ""))
            {
                selected = "selected";
            }
            <option @selected value="@language.LanguageId">@language.GetDisplayName()</option>
        }
    }
</select>

 

You must be logged in to post in the forum