An ode to Sitecore Support and a different way to have multiple placeholders for tabs

This post is dedicated to Sitecore Support. Over the past 6 or 7 seven years of Sitecore development I’ve thrown dozens of loaded hot potatoes over to support to solve for me, and they have come through every time. So without sounding overly melodramatic, here’s to Sitecore Support – thanks for saving my hide – many times over.

And here’s the latest lifesaver.

A content feature that is often requested in Sitecore is a tabs module. A tabs module is a pretty common component of any website, and in Sitecore you can custom build a tabs module any way you want. A pretty basic one would be to allow the user to add tabs, and then add text underneath each tab via a text field. Using the page editor, we can make a nice easy-to-use tabs module.

A basic tabs sublayout, that allows the user to add multiple tabs and then add content/text underneath.
A basic tabs sublayout, that allows the user to add multiple tabs and then add content/text underneath.

What would be really more flexible if we could instead swap out the text field with a placeholder and then allow the user to add whatever module they want – multiple modules, if need be. The only problem is that we don’t know how many tabs the user would add, so we would need to be able to add them dynamically. As most people that have been working with Sitecore knows, the layout engine of the page editor has some limitations with being able to render multiple placeholders with the same key. If you’re not aware of this, you can read all about it on Nick Wesselman’s Blog: http://bit.ly/1jUMo2P.

So a good way to do this would be just to use this prototype and then wrap it around a repeater – you can also use a regular placeholder, but then you have to assign the key value manually in the repeater. I’m using the regular placeholder, just to illustrate this example. Whether you use the regular placeholder or the dynamic one, you have to add the GetDynamicKeyAllowedRenderings to the getPlaceholderRenderings pipeline, so you can get the correct allowed renderings for the placeholder:


protected void rptrTimelineItemsEdit_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        Item item = (Item)e.Item.DataItem; 

        Placeholder scPlaceHolder = (Placeholder)e.Item.FindControl("scPlc");
        scPlaceHolder.Key = "itemcontent" + item.ID.ToString().ToLower(); 

    }
} 

If you don’t use the page editor, this works great. However, if you use the page editor, you end up getting an error when adding any other sublayouts:

Could not find the rendering in the HTML loaded from server PlaceholderChromeType.js:601
Sitecore.PageModes.ChromeTypes.Placeholder.Sitecore.PageModes.ChromeTypes.ChromeType.extend._frameLoaded

It pointed me the file, but I wasn’t entirely sure what the issue was. When I put the placeholder outside of a repeater, it worked fine. So I contacted Sitecore Support. They told me that the issue only occurs when a repeater is placed on a sublayout that is inserted into a placeholder. If the Repeater is added to a layout directly than everything works fine. So then problem exists when placeholder from the repeater is nested in another placeholder. They provided me with a replacement of the PlaceholderChromeType.js file that goes to replace the existing one in:

\Website\sitecore\shell\Applications\Page Modes\ChromeTypes\PlaceholderChromeType.js

Also, you have to make sure that any placeholders created this way must have the keyword ‘dynamic’ in it, and all static placeholders must have names that do not contain “dynamic” substring, as they will be processed as dynamical.

The updated .js file can be found here: https://drive.google.com/file/d/0B1J6kaxsX5DoMERXc2JWaUlCMDQ/edit?usp=sharing

Once done, the placeholders render beautifully:

The multiple placeholders appear correctly and and show the correct renderings when clicked.
The multiple placeholders appear correctly and and show the correct renderings when clicked.

This is obviously not limited to a tabs structure, but can be used in multiple places to allow dynamic content, such as slideshows, timeline controls, etc.

Note: This indeed has been reported as a bug, and is not currently in the queue for release, as far as I’m told. This was tested and working great in version 6.6 rev 120918

13 thoughts on “An ode to Sitecore Support and a different way to have multiple placeholders for tabs

  1. Hi Mickey, I’m having a similar issue so im glad i found your post, by key word do you mean the Key=”” property so Key=”dynamic_blah” could you elaborate on this or provide an example 🙂

  2. I have dynamic placeholders working fine, although it does not seem possible to make them work in a repeater, I have followed your blog and also used the standard sc placeholder and still no joy. Has this been tested with Sitecore 7.2?

    1. Hi Luke, I have not actually tested in Sitecore 7+ – the specific fix is validated only for 6.6 rev 120918 – I’m in the process of doing something like this for Sitecore 8, so I will keep you posted….

    2. If anyone else has issues with this, I found the issue was in the javascript it was escaping the placeholder name and removing the { } in the Guid, which is why it could not find the placeholder to insert the html.

      var str = this.placeholderKey();

      1. Great find – hopefully this is fixed in Sitecore 8, as is the original bug!

      1. HI Rob, the mechanism of how the dynamic placeholder works really haven’t changed, and I have this working in 8 (update 3). The only thing I can think of is that the JS file has been updated, and does not recognize the new placeholder names from the page source.

  3. One other problem I have in my solution is that I want to insert a sublayout with placeholders into the repeater placeholder… Seems it will be very hard to get this to work unless you have any ideas? The placeholders almost need to inherit each other.

    1. HI Luke, are you trying to place sublayouts with placeholders with same key names? If so, you will need to implement the dynamic placeholders (through a pipeline). If you are inserting them with the sublayouts that will generate the placeholders, then you can just assign them different keys also, no?

  4. I already have dynamic placeholders working which takes the GUID from the rendering id I think. I ued this: http://johnnewcombe.net/blog/sitecore-part-3.

    The problem is I implemented your solution that works for placeholders within a repeater, but if you place a sublayout that contains placeholders in one of those placeholders in the repeater, you get the error about not being able to insert html. I guess this sublayout would somehow need to know that has been inserted into a databound control to use the dynamic name in the placeholder key. Also it would need a key that is dynamic because it would be repeated.

  5. Has anyone got this working with forms within a repeater placeholder? It works fine for normal content but when I add a form the button click events do not wire up correctly?

Leave a comment