0

We have a following structure :

master:/content/market1/myfolder
master:/content/market2/myfolder
master:/content/market3/myfolder

etc.

I would like to add renderings for all items within "myfolder" and also for all markets using PowerShell script (there is like 15 items in myfolder and also like 20 markets, so nobody wants to do it manually).

I am pretty new here. Did someone experienced something like this?

Thank you very much.

  • Do you want just to copy items from one folder into another folder? – adarsh Mar 26 '18 at 7:11
  • no i just want to add renderings for all items in "myfolder". I have created rendering which i want to add to all items, – Martin Fric Mar 26 '18 at 7:19
  • did you created rendering on standard values or are totally different renderings for every item? – Vlad Iobagiu Mar 26 '18 at 7:50
  • it is the same rendering for all items. I have created one , which is controller rendering. But i want to add it for all items (not manually) – Martin Fric Mar 26 '18 at 7:58
  • You will need a specific placeholder so as to know where to add the new rendering. – adarsh Mar 26 '18 at 8:03
3

You can use the below script to add rendering to the items.

$containerArray = @("{Sitecore Id goes here}","{Sitecore Id goes here}","{Sitecore Id goes here}")

foreach ($element in $containerArray){
    $items = Get-ChildItem -ID $element.ID -Language "en"

    $addedRendering = Get-Item "master:path to your rendering goes here" | New-Rendering -Placeholder "contentMain" 

    foreach($item in $items){
        Write-Host "Processing item: " $item.Name
        Add-Rendering -Item $item -PlaceHolder "contentMain" -Rendering $renderingItem
    }
}

Note

  1. Replace the {Sitecore Id goes here} with the Id of the containers.

  2. You can change the language if required.

  3. You need to specify the name of the placeholder so that it knows where to add the rendering.

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.