In this blog post I am going to explain how to get all the items (referrers) which are referring to a particular item (may be template, sublayout or rendering etc.) in Sitecore. There are few ways to achieve this goal:
Comments and suggestions are most welcome. Happy coding!
- Using Sitecore Content Editor UI
- Writing custom C# code
- Using Sitecore Powershell Console Module
- Using Sitecore Content Editor UI: The simplest way of seeing these referrer links is to go to that particular item and go to the Navigation Strip and then click on Links. This should show you all the items (referrers) that point to this current item and all the items that the current items points to (references).
- Writing custom C# code: Below function GetReferrers(string itemId) takes item id as input parameter and return the list of items which are pointing to this particular item.
public Item[] GetReferrers(string itemId) { Item item = Sitecore.Data.Database.GetDatabase("master").GetItem(new Sitecore.Data.ID(itemId)); // getting all linked Items that refer to the Item ItemLink[] itemLinks = Globals.LinkDatabase.GetReferrers(item); if (itemLinks == null) { return null; } else { ArrayList items = new ArrayList(itemLinks.Length); foreach (ItemLink itemLink in itemLinks) { // comparing the database name of the linked Item if (itemLink.SourceDatabaseName == "master") { Item linkItem = Sitecore.Data.Database.GetDatabase("master").Items[itemLink.SourceItemID]; if (linkItem != null) { items.Add(linkItem); } } } return (Item[])items.ToArray(typeof(Item)); } }
- Using Sitecore Powershell Console Module: Download Sitecore Powershell Console Module from Sitecore MarketPlace and install the package. Go to Start > Development Tools > PowerShell ISE.
Enter below powershell script in script field and execute.$props = @{ InfoTitle = "Referrers" InfoDescription = "Lists all items that are using this item" PageSize = 25 } function Get-ItemReferrers { $item = Get-Item -Path "/sitecore/templates/Launch Sitecore/Job Function" $linkDb = [Sitecore.Globals]::LinkDatabase $links = $linkDb.GetReferrers($item) foreach($link in $links){ $linkedItem = Get-Item -Path master:\ -ID $link.SourceItemID $linkedItem } } $items = Get-ItemReferrers $items | Show-ListView @props -Property @{Label="Name"; Expression={$_.DisplayName} }, @{Label="Updated"; Expression={$_.__Updated} }, @{Label="Updated by"; Expression={$_."__Updated by"} }, @{Label="Created"; Expression={$_.__Created} }, @{Label="Created by"; Expression={$_."__Created by"} }, @{Label="Path"; Expression={$_.ItemPath} } Close-Window
Comments and suggestions are most welcome. Happy coding!
Balıkesir
ReplyDeleteBursa
Mersin
Konya
Van
Y0SY
çankırı
ReplyDeleteelazığ
antep
ağrı
van
N6X
https://titandijital.com.tr/
ReplyDeletenevşehir parça eşya taşıma
bolu parça eşya taşıma
batman parça eşya taşıma
bayburt parça eşya taşıma
F302