0

how could I get data source of content that is used in page using Sitecore PowerShell Extensions?

2 Answers 2

1

There can be multiple renderings on the page.

They can be defined on Shared Layout and Final layout.

Here is sample code which goes through both of them and lists full paths of datasources:

$language = ...
$path = ...

$page = Get-Item -Path $path  -Language $language

$device = Get-LayoutDevice -Default

$renderings = @()
$renderings += Get-Rendering -Item $page -Device $device 
$renderings += Get-Rendering -Item $page -FinalLayout -Device $device 

foreach($rendering in $renderings)
{
    if ($rendering.Datasource -ne $null)
    {
        $datasourceItem = Get-Item master: -ID $rendering.Datasource -language $language
        if ($datasourceItem -ne $null) 
        {
            $datasourceItem.Paths.FullPath
        }
    }
}
0

I came across a similar scenario where I need to get data sources for the final layout.

The answer given by Marek Musielak is valid. However, I did tweak it as per need.

$contentItem = Get-Item -Path "/sitecore/content/Home" -Language "en"

$renderings = Get-Rendering -Item $contentItem -FinalLayout

foreach($rendering in $renderings)
{
    if (![string]::IsNullOrEmpty($rendering.Datasource))
    {
        Get-Item -Path "master:" -ID $rendering.Datasource
    }
}

Hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.