Last Wednesday I had the pleasure of presenting Sitecore PowerShell Extensions (SPE) at the Milwaukee Sitecore Meetup. The goal of my presentation was to share how easy it is to add, execute and reuse PowerShell scripts in SPE, and I did this on version 3.0 of SPE in a Sitecore XP 8 instance.
In my presentation, I showed how quickly one can add a custom Sitecore gutter icon with SPE, and used the following script to demonstrate that:
<# .NAME Item Has 20 Or More Sub-items Gutter .SYNOPSIS Renders gutters indicated whether the item has more than 20 sub-items. .NOTES Mike Reynolds #> $item = Get-Item . $gutter = New-Object Sitecore.Shell.Applications.ContentEditor.Gutters.GutterIconDescriptor if($item.Children.Count -gt 20) { $gutter.Icon = "Applications/16x16/delete.png" $gutter.Tooltip = "This Item has more than 20 sub-items!" } else { $gutter.Icon = "Applications/16x16/check2.png" $gutter.Tooltip = "This Item has 20 or less sub-items." } $gutter
The script above creates a new Sitecore.Shell.Applications.ContentEditor.Gutters.GutterIconDescriptor instance — this class is defined in Sitecore.Kernel.dll — and sets a certain icon and tooltip on it if the context Item has more than 20 sub-items. If the Item has 20 or less sub-items, a different icon and tooltip are used.
The script then outputs the GutterIconDescriptor instance.
I then saved the above script to the Gutter integration point in my SPE module:
Now that it’s saved, we have to sync it to the Sitecore Gutter:
We should be good to go! Let’s test this out!
I went to my content tree; right-clicked in the gutter area; and was presented with the gutter menu:
After clicking my new gutter menu option, I was presented with gutter icons next to Items in my tree:
As you can see, the Item with the X icon has more than 20 sub-items:
For comparison, the following Item has a green check-mark icon next to it which indicates it has 20 or less sub-items (this Item actually has 10 sub-items):
If you have any thoughts and/or suggestions on this, or have ideas for other gutter icon scripts that can be incorporated into SPE, please share in a comment.
If you would like to watch the Milwaukee Sitecore Meetup presentation where I showed the above — you’ll also get to see some cool Sitecore PowerShell Extensions stuff from Adam Brauer, Senior Product Engineer at Active Commerce, in this presentation as well — have a look below:
Until next time, keep on learning and sharing!
[…] also wrote a post on how to add to the Sitecore Gutter using the Sitecore PowerShell Extensions module. I recommend […]