Add Sitecore Rendering in Bulk

Hey Sitecorians,

Hope you’re doing well with Sitecore.

Many a time we need an option to have some utility that will do the job easily and save the time for the content team to get things done faster and take the bunch out of the plate. One such requirement was for adding the sub-layout/rendering in bulk. I quickly built a utility that will do the job easier for the content team.

A simple utility that will do the following:

  1. Add Rendering
  2. Assign placeholder key to a newly added rendering
  3. Add appropriate data-source value

The utility will ask for the following:

  1. Parent-item ID
  2. Template ID – Which items, defined from the given template need to have the rendering.
  3. Rendering ID
  4. Data-Source Value
  5. Placeholder Key

Let me quickly go-through with what I did in above code.

  1. Get the default device.
  2. Iterate through all the child items
  3. Check If the item does have any other rendering — If not then continue with the next item
  4. Check If Item does have the given rendering already assigned
  5. Get the layout definition
  6. Get the device definition — This is based on the default device. Default device ID is same for all the Sitecore Versions.
  7. If rendering already exist – Get the rendering and update Data-Source Value and Placeholder Key otherwise Add the new rendering into Device Definition
  8. Save the changes.

There are many things not done in this as I was sure this will do the job and carefully executed by the right person. If you are planning to give it to someone who can enter anything in the text-box then you need to have the proper error-handling, null check, and Template/Item ID check.

aspx file — Download

Happy Sitecoring!


Leave a Reply

Your email address will not be published. Required fields are marked *