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.

6
  • Do you want just to copy items from one folder into another folder?
    – adarsh
    Mar 26, 2018 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, Mar 26, 2018 at 7:19
  • did you created rendering on standard values or are totally different renderings for every item? Mar 26, 2018 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) Mar 26, 2018 at 7:58
  • You will need a specific placeholder so as to know where to add the new rendering.
    – adarsh
    Mar 26, 2018 at 8:03

1 Answer 1

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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