Filter Your Renderings…Today!

Don’t you want to save your content authors time?  Don’t you want them to love you?  This will certainly help!  This small snippet will get you on the god / goddess path to stardome.

Let’s get that rendering!

In Page Editor / Experience Editor, when adding a rendering you click on the “Add To Here” button which launches the SelectRendering dialog.  This gives us a nice display of the renderings that we can use for this placeholder, that is if we have any allowable controls set on the placeholder.  If you do not use allowable controls you need to drill down into the tree and find your rendering.  Either way, it would be nice if I could just tell Sitecore what I wanted.  Unfortunately I have not mastered Siri for Sitecore yet, but I have added some functionality to allow us to type what we like.  Take a look at the screenshot below, I have modified it to include a text box near the top where you can by name, filter your renderings.  With every keystroke it begins to filter down your renderings.

SelectRendering

To implement this change you simply need to modify the SelectRendering.xml which is located here: /sitecore/shell/applications/dialogs/selectRendering/selectRendering.xml.





<div style="padding-top:15px;padding-bottom:15px;">
	Filter Your Renderings:
	<input type="text" id="filterRenderings"/>
	<script type="text/javascript">
		document.observe('dom:loaded', function() {
			Event.observe(document, 'keyup', function(evt) {
				var elements = $$('span.scDisplayName');
				var arrayLength = elements.length;
				var some = '';
				var i = 0;
				var inputValue = $$('#filterRenderings')[0].value.toLowerCase();
				if (inputValue.length != -1) {
					while (some == '') {
						var name = elements[i].innerText.toLowerCase();
						if (name.indexOf(inputValue) == -1) {
							elements[i].up().style.display = "none";
						} else {
							elements[i].up().style.display = "block";
						}
						i++;
						if (i == arrayLength) {
							some = 'something';
						}
					}
				}
			});
		});
	</script>
</div>




I Don’t Always Use Allowable Controls

In this case, why have the content author dig through the tree every time?  Without allowable controls the dialog will not display any renderings on the right side, therefore they have to remember where it is that rendering resides, in a matured solution that can be a cumbersome process.  We do use allowable controls on the Collette site in many places but not all due to dynamic placeholders.  Because of this I have modified the codebeside for the SelectRendering dialog in such a way that if no allowable controls are set, then bring back the full suite of renderings. This allows them to open this dialog, type what they want to filter the renderings then double click their selection. Much much faster. The concern is the content author may put a rendering where it doesn’t belong, I thought about this but it comes down to training. Components “should” work across different pages if they are designed correctly. This feature in addition to the name filtering that I talked about above has helped our team here at Collette.

Feel free to reach out with any questions, lastly I leave you with our codebeside. You need to point the codebeside in the SelectRendering.xml to your new class file which needs to inherit from Sitecore’s class. From here you can override the OnLoad method. You can see later down in the code I am doing a GetDescendants() call to a certain location. Here you will want to change that location to best fit your solution.

Enjoy and Happy New Year Sitecorians! 🙂


protected override void OnLoad(EventArgs e)
{
	Assert.ArgumentNotNull(e, "e");
	base.OnLoad(e);
	if (!Context.ClientPage.IsEvent)
	{
		this.IsOpenPropertiesChecked = Registry.GetBool("/Current_User/SelectRendering/IsOpenPropertiesChecked");
		SelectRenderingOptions options = SelectItemOptions.Parse<SelectRenderingOptions>();
		if (options.ShowOpenProperties)
		{
			this.OpenPropertiesBorder.Visible = true;
			this.OpenProperties.Checked = this.IsOpenPropertiesChecked;
		}
		if (options.ShowPlaceholderName)
		{
			this.PlaceholderNameBorder.Visible = true;
			this.PlaceholderName.Value = options.PlaceholderName;
		}
		if (!options.ShowTree)
		{
			this.TreeviewContainer.Class = string.Empty;
			this.TreeviewContainer.Visible = false;
			this.TreeSplitter.Visible = false;
			GridPanel parent = this.TreeviewContainer.Parent as GridPanel;
			if (parent != null)
			{
				parent.SetExtensibleProperty(this.TreeviewContainer, "class", "scDisplayNone");
			}
			this.Renderings.InnerHtml = this.RenderPreviews(options.Items);
		}
		else
		{

			var renderingItems = Enumerable.ToList(Database.GetDatabase("master").GetItem("/sitecore/layout/Renderings/Collette")
				.Axes.GetDescendants()).Where(x => ItemUtil.IsRenderingItem(x)).ToArray();

			ItemCollection renderings = new ItemCollection();
			renderings.AddRange(renderingItems);

			Renderings.InnerHtml = this.RenderPreviews(renderings);
		}
		this.SetOpenPropertiesState(options.SelectedItem);
	}
}

2 thoughts on “Filter Your Renderings…Today!

  1. Rey Rahadian

    Nice idea.

    Any chance of thinking to add “recently used renderings” section as well ? I think that would also lessen the number of times the content author would have to search for their frequently used renderings.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s