Created
May 10, 2013 05:54
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ 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> | |
<% | |
} | |
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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