Dynamic Placeholder Keys

This post is just a bookmark for ourselves to this very interesting solution by Nick Wesselman to resolve the problem we have in Sitecore when adding multiple sublayouts of the same type into another sublayout.
Here is his solution: http://www.techphoria414.com/Blog/2011/August/Dynamic_Placeholder_Keys_Prototype

Even more goodies about Page Editor from Nick in this must-see post: http://www.techphoria414.com/Blog/2012/May/Sitecore_Page_Editor_Unleashed


How to change the sc:link tag to render a specific type when using page editor

The sc:link field provided by Sitecore in conjunction with the ‘General Link’ field type is a really flexible combination. When setting a field type in a template as ‘General Link’, it gives a variety of options for links that can be inserted in that field:

Different types of link insert options

When editing an item through the content editor, clicking on each different type of link will open a different window, with the appropriate fields to enter information:

External Link Window

Internal Link Window

Media Link Window

However, there is no option to set the link type in the control when placing it in the sublayout – so users that edit the item in page editor always see the first type (which is ‘internal’) or if the item was already edited via the content editor, they will see the type of link that was set by the user when they created/updated it.

Edit Link Option when using Page Editor

I thought this was odd behavior  and researched a little bit to find that the foundation of the field was still the xsl link field – which did have a linktype. A little more research led me to find that you can set it to a certain type for the users that use page editor, by putting in the definition in the raw values option.

So, to do this, you will need to create a standard values for the template. Once you do that, go to View and check ‘Raw Values’. Once checked, go into the field in your template, and put the following text:

<link linktype="external" url="" anchor="" target="" />

Now, when you go into page editor, and you click on ‘edit link’ icon, it will open the type that you set. The different link types are:

  • internal
  • external
  • mailto
  • anchor
  • javascript

Each of these have different attributes as well – the example above shows the values for when the linktype is ‘external’, which has options for url, anchor and target.

Here are the attributes available for all the types:

<link text="" linktype="internal" url="" anchor="" querystring="" title="" class="" target="" id="[sitecore item id]" />
<link text="" linktype="media" url="" title="" class="" target="" id="[media item id]"/>
<link text="" linktype="external" url="" anchor="" title="" class="" target="" />
<link text="" linktype="anchor" url="" anchor="" title="" class="" /> 
<link text="" linktype="mailto" url="" anchor="" title="" class="" />
<link text="" linktype="javascript" url="" anchor="" title="" class="" />

This still only gives you the option in the page editor to have only one type of link. This is OK for most situations, I would imagine, and the types can always be changed in the content editor. If you know of a way to achieve this in the page editor using the command buttons, drop me a note!

Sitecore sc:editframe empty DIV workaround

The sitecore page editor has come a long way since it was first introduced. It is a very useful tool for content editors to edit pages, as opposed to the content editor, which can seem daunting to a business user. Page editor comes with a lot of options for configurations – one of these options is to have the user be able to enter a new item into sublayout, as a child of the existing item. This is acheived by adding an sc:ediframe tag in the sublayout:

 <sc:EditFrameID="editLinks"runat="server"Buttons="/sitecore/content/Applications/WebEdit/Edit Frame Buttons/MySitecoreProject">

This works great, when you already have items in there, so the <div> that contains the content has enough of an area for the mouseover to work.

When the DIV has content, it has mouseover area that can be used.

However, if you don’t have any items in there, the <div> is collapsed, so there is no area to mouseover on, and hence the context menu does not appear.

No <div> outline, so the user doesn’t know where to mouseover to see the context menu.

The very simple workaround for this is to have an instructions text, and/or an image menu icon, which hovered on opens up the sitecore page edit menu.

Simple image, and text, conditionally displayed

On the resulting .ascx sublayout, the code would be:

<sc:EditFrame ID="editLinks" runat="server" Buttons="/sitecore/content/Applications/WebEdit/Edit Frame Buttons/MyProjectName">

<asp:Panel ID="pnlInstructions" runat="server" Visible="false"><img src="/images/menu.gif" />Insert new items here by clicking on the menu button on the left.</asp:Panel>

In the code behind, you would then only display the content if in editing mode:

if (Sitecore.Context.PageMode.IsPageEditor || Sitecore.Context.PageMode.IsPageEditorEditing)
     pnlInstructions.Visible = true;

Subsequently, you can also make the instructions text come directly from the sitecore item – make a field called “Instruction”, and insert an sc:text tag into the panel:

<sc:EditFrame ID="editLinks" runat="server" Buttons="/sitecore/content/Applications/WebEdit/Edit Frame Buttons/MyProjectName"></span>

<asp:Panel ID="pnlInstructions" runat="server" Visible="false"><img src="/images/menu.gif" /><sc:Text ID="scInstruction" runat="server" Field="Instruction" /></asp:Panel>