This can be an incredibly time consuming operation and daunting operation. Especially if those items contain sub items which need images which need to link to other items, etc, etc. Lots of manual content entry which is costly, prone to error, and lacks any sort of verification or re-usability.
So enter Powershell. This is the kind of scenario Powershell really shines at. Fast (to write) scripts for one or few time use with the ability to load your content into Sitecore in the proverbial blink of an eye. Thankfully, the folks at cognifide made us a Sitecore powershell extension to help out.
One of the tasks that is surely familiar to any Sitecore admin is attaching controls to objects. While going through the UI works it is incredibly slow. Not something you want to do dozens, much less hundreds of times.
Well, it turns out it isn't that super hard. We're going to use Powershell Here Strings to store a generic Sitecore rendering XML and create/replace the GUIDs we need to. You can see the Sitecore specific way of doing this using their API via John West's blog on the subject.
The script is below, we have a group of pages and a group of controls. Our controls that we need to add are named the same as our pages. We simply find them, retrieve their sitecore ID and create a new GUID for the actual control object.
There are 3 attributes at play here in the XML we care about. The first is the ID, that is the actual Sitecore item we are setting. The second is the UID , this is a GUID unique to this instance of the rendering, hence why we generated a new GUID. The second is the s:ds attribute, which is our datasource for our Sitecore component. The fourth, you may notice, is the s:ph which is the placeholder attribute.
You might be wondering where we got the the XML in the first place. I "cheated" by pulling the data from the Sitecore objects .__Renderings field.
Ta-Da! Hours saved from mainly attaching many, many controls.