0

I wonder when I copy final renderings, what does happen with the datasource, does this will be copy also datasource or not?

New-UsingBlock (New-Object Sitecore.Security.Accounts.UserSwitcher $elevatedUser) {
function Copy-FinalRenderings {
param(
    [Item]$baseLangItem,
    [Item]$newLangItem
)

if($baseLangItem.TemplateID -in $templateIds)
{
    $newLangItem.Editing.BeginEdit()
    $newLangItem.Fields["__Final Renderings"].Value = $baseLangItem.Fields["__Final Renderings"].Value
    $newLangItem.Editing.EndEdit()
}
}
2
  • Can you please add more details to your questions? What kind of issues you are getting? Commented May 25, 2022 at 7:03
  • Is datasource copied to with final renderings? Commented May 25, 2022 at 7:12

2 Answers 2

2

You are copying just a field in an item. This will not copy other items, like related datasources.

However, the relationship to the datasource items will remain as this is based on guids inside the final renderings field.

I think based on your code sample we can assume you are copying final renderings between language versions. In that case, the datasource relation will be fine. It will still point towards the original datasource but Sitecore will take the context language when rendering it.

2
  • Does this means the content will remain in only original version of data source and content will not be visible? Commented May 25, 2022 at 14:13
  • No new versions will be created. If you have language fallback enabled, that is not an issue. Otherwise the datasources will not be found indeed.
    – Gatogordo
    Commented May 25, 2022 at 15:26
2

Along with the answer given by @Gatogordo, want to add this like If you want the list of data sources used in your rendering, then you can use the following Powershell Command, which will give you the output of the data source used.

$defaultLayout = Get-LayoutDevice -Default

$rootItem = Get-Item -Path "master:" -ID "<your-item-id>"

Get-Rendering -Item $rootItem -Device $defaultLayout -FinalLayout | Select-Object -Property DataSource

Then you can copy those items into your new location.

1
  • The problem is with this the content is not copied to newly created page item language version Commented May 25, 2022 at 14:35

Your Answer

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

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