The Sitecore PageEditor and Preview interfaces feature a language selector button that triggers a "dropdown"/overlay menu where the user can select a language. How do I replicate this behavior?
(I set out to answer this question, and came up with a solution. Posting to SOF for comment/enhancement.)
You can see how Sitecore does it in the
Sitecore.Client
assembly,Sitecore.Shell.Applications.WebEdit.Commands.ChangeLanguage
andSitecore.Shell.Applications.WebEdit.Commands.SetLanguage
.You'll need to create two commands of your own for this. One command is associated with the button, one is executed when a subitem is selected. The example is based on a scenario of changing a country cookie.
ChangeCountry Command
First, the command to display the menu. You can see that it displays a
Menu
with dynamic options. OverridingGetHeader
andGetIcon
allows the button itself to be dynamic based on the user's current selection.In either Commands.config or an include file, register the new command.
Change Country Button
Create a new Chunk and Button under
/sitecore/content/Applications/WebEdit/Ribbons/WebEdit/Experience
. This ribbon strip is referenced/replicated in Preview mode as well. The button will use the following properties:The Click field must match the name of your command, and the ID field must match the element ID provided in the
SheerResponse.ShowPopup
call above.SetCountry Command
Next is the command that will be called when an item in your menu/dropdown is selected.
In our example, we're setting a cookie based on the selected value and reloading the page. The value passed in is based on the click event associated with the menu item in
ChangeCountry
. Likewise, the name of the command when configured needs to match what was used in theChangeCountry
click event.