Skip to content

Instantly share code, notes, and snippets.

@DaveGoosem
Created May 10, 2013 05:54
Show Gist options
  • Save DaveGoosem/5552643 to your computer and use it in GitHub Desktop.
Save DaveGoosem/5552643 to your computer and use it in GitHub Desktop.
Example Sitecore control using datasources and Multilists Note: Multilists need to use Sitecore Item IDs find items.
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="KnowledgeBaseListing.ascx.cs" Inherits="DigiconNew.layouts.Sublayouts.Controls.KnowledgeBaseListing" %>
<% foreach (var kbcategory in KBCategories)
{
%>
<div class="article">
<div class="article-title">
<h3>
<a href='<%= GetURL(kbcategory) %>'><%= kbcategory["Article Title"]%></a>
</h3>
</div>
<div class="kb-summary"><%= kbcategory["Article Teaser"]%></div>
</div>
<%
}
%>
using System;
using System.Collections.Generic;
using Sitecore.Data.Items;
using System.Linq;
using Sitecore.Web.UI.WebControls;
using Sitecore.Links;
namespace DigiconNew.layouts.Sublayouts.Controls
{
public partial class KnowledgeBaseListing : System.Web.UI.UserControl
{
public List<Item> KBCategories = new List<Item>();
protected void Page_Load(object sender, EventArgs e)
{
var item = DataSourceItem ?? Sitecore.Context.Item;
string query = "/sitecore/content//*[@@templatename = 'Knowledgebase Article' AND contains (@Tags, '" + item.ID + "')]";
Item[] itemsToShow = Sitecore.Context.Database.SelectItems(query);
KBCategories = itemsToShow.ToList();
}
protected string DataSource
{
get { return ((Sublayout)this.Parent).DataSource; }
}
protected Item DataSourceItem
{
get { return Sitecore.Context.Database.GetItem(DataSource); }
}
public string GetURL(Item item)
{
return Sitecore.Links.LinkManager.GetItemUrl(item);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment