Get Languages

Get Languages

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Database
  • Sitecore.Data.Items.Item
  • Sitecore.TemplateIDs
  • Sitecore.StringUtil
  • System.String

Languages C# Web Control Code

Sitecore.Data.Items.Item item = this.GetItem();
if (item == null) return;

string query = System.String.Format("//*[@@templateid='{0}']", Sitecore.TemplateIDs.Language);

Sitecore.Data.Database db = Sitecore.Context.Database;
Sitecore.Data.Items.Item[] descendants = db.SelectItems(query);
if (descendants == null) return;

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("C# Web Control Real-time Output");
output.RenderEndTag();

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
string displayName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
//using : for colon and   for space
output.Write("{0}: {1}", "Item", displayName);
output.RenderEndTag(); //P

foreach (Sitecore.Data.Items.Item descendant in descendants)
{
    output.Write("{0}&#58;&#160;{1}", "Configured Language", "<b>" + descendant.DisplayName + "</b><br/>");
}

output.RenderEndTag(); //Div


Languages C# Web Control Output

Configured Language: en