0

I have to get data of rendering parameters used by a specific sub-layout. Is there a way to get all items which are using a particular Sublayout.

Example: I have a Sublayout "SiteHeader" and it has a rendering parameter template with a parameter "show image" checkbox. I need to fetch all the items which are using this "SiteHeader" Sublayout and the value of "show image" field i.e. if it is checked or not.

2 Answers 2

8

Yes you can. I would go through the Links database in order to do that, like this:

$rendering = Get-Item -Path '{093B75B4-5060-4F3D-AFAB-DCA4999F7E96}'
$items = @()
[Sitecore.Globals]::LinkDatabase.GetReferrers($rendering) | 
    Where-Object -FilterScript { $_.SourceFieldId -eq '{04BF00DB-F5FB-41F7-8AB7-22408372A981}' -or $_.SourceFieldId -eq '{F1A1FE9E-A60C-4DDB-A3A0-BB5B29FE732E}' } | 
    Select-Object -Property SourceItemID -Unique |
    ForEach-Object {
        $item = Get-Item -Path $_.SourceItemId
        #you can add further filtering code here
        $items += $item
    }

$items

Replace the ID on the first line with your Sublayouts ID. Then that goes to the link database to find all items that links to this item, filters them to only take the shared and final renderings fields, and selects the unique rows. Then it gets all the items and adds it to an array.

edit: made it a bit clearer and fetched the items rather than just the ids

2

Likely very similar output as @morten.engel's response, but Sitecore Powershell Extensions has a Get-ItemReferrer command:

$allReferrers = Get-ItemReferrer -ID '{093B75B4-5060-4F3D-AFAB-DCA4999F7E96}'

The above will return all referrers to the item specified by the ID. If you need to filter the referrers based on additional fields:

$checkedReferrers = Get-ItemReferrer -ID '{093B75B4-5060-4F3D-AFAB-DCA4999F7E96}' | Where-Object {$_.Fields["Show Image"].Value -eq 'checked'}

Also, if you need to know or filter based on the actual field referencing the specific item, Get-ItemReferrer also has a -ItemLink switch that will return Links instead of Items (almost exact to @morten.engel's answer):

$filteredFieldReferrers = Get-ItemReferrer -ID '{093B75B4-5060-4F3D-AFAB-DCA4999F7E96}' -ItemLink 
| Where-Object { $_.SourceFieldId -eq '{04BF00DB-F5FB-41F7-8AB7-22408372A981}' -or $_.SourceFieldId -eq '{F1A1FE9E-A60C-4DDB-A3A0-BB5B29FE732E}' } 
| Select-Object -Property SourceItemID -Unique | Get-Item

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.