A question came up on the Sitecore community today about being able to publish multiple items in one go. As a developer you can do this easily in Sitecore Rocks as you can multi-select items in the tree and publish fromn the right-click menu. But in the Content Editor, there is no option to multi-select items.
You can of-course publish all sub-items of an item, and you can publish related items also. An Incremental publish, runs through the current publish queue. But none of those options would allow the content editor to select a disparate set of items and publish them. It got me thinking, I wonder if I could do this with a Sitecore Powershell Extensions module/script.
If you haven’t heard of it yet, Sitecore Powershell Extensions is, IMO, the best market place module you can get for Sitecore. I can’t imagine how I used to get on without it being installed! Watch this for a great overview of SPE.
###SPE Module
At its core, an SPE module, is a group of scripts that work together to provide some functionality. In our case, we want to be able to:
- Create a new Publish Queue
- Add single items to the queue
- Add an item and all its children to the queue
- Publish/Process and clear the queue
###Session Persistency
A really nice feature of SPE is that you can have session persistency, that is variables set in one script can be read by another script. This allows us to have multiple steps.
###Muilti-Item Publish Module
Here are the scripts in our multi-item publish module:
So we start with a script that starts a new publish queue. For the queue, we will just use 2 arrays, 1 for the single items, and 1 for recursive publishes.
1 | # Initialize the arrays |
Then we want to just add the currently selected item to each array:
1 | # Add Single Item |
1 | # Add Branch Item |
Finally - we want to process the items and publish them to all publish targets:
1 | $publishingTargetsFolderId = New-Object Sitecore.Data.ID "{D9E44555-02A6-407A-B4FC-96B9026CAADD}" |
And hey presto, we have a module that allows the user to right-click items and queue them for publishing, and then just process that queue.
###Using the Module
Now a content editor can right-click an item, go to the Publishing
menu under Scripts
:
Then add items:
Finally, publish and clear the queue:
At the end, we give an indication of the items processed:
###This is just a start
This really was more for fun and to see if it was possible, so there are a number of features mssing that we might want to add. There is no language parameter, we might want to limit the publish targets etc… We could have better reporting on what is getting published too - but its a nice start.
The module code was losely based on the Package Generator
module that ships with SPE.
– Richard Seal
.