Sitecore PageEditor 및 Preview 인터페이스에는 사용자가 언어를 선택할 수있는 "드롭 다운"/ 오버레이 메뉴를 트리거하는 언어 선택기 버튼이 있습니다. 이 동작을 어떻게 복제합니까? 드롭 다운 메뉴를 사용하여 Sitecore 리본 버튼을 만드는 방법은 무엇입니까?
는 (나는이 질문에 대한 답을 제시하고 해결책을했다. 코멘트/향상을위한 SOF에 게시.)답변
Sitecore에서, Sitecore.Client
어셈블리에 Sitecore.Shell.Applications.WebEdit.Commands.ChangeLanguage
및 Sitecore.Shell.Applications.WebEdit.Commands.SetLanguage
그것을 어떻게하는지 당신은 볼 수 있습니다.
이렇게하려면 두 가지 명령을 만들어야합니다. 하나의 명령은 버튼과 연관되어 있으며, 하나의 명령은 하위 항목이 선택 될 때 실행됩니다. 이 예제는 국가 별 쿠키를 변경하는 시나리오를 기반으로합니다.
ChangeCountry 명령
첫째, 명령 메뉴를 표시합니다. 동적 옵션을 사용하여 Menu
을 표시하는 것을 볼 수 있습니다. GetHeader
및 GetIcon
을 재정의하면 버튼 자체가 사용자의 현재 선택에 따라 동적으로 바뀝니다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sitecore.Shell.Applications.WebEdit.Commands;
using Sitecore.Diagnostics;
using Sitecore.Data.Items;
using Sitecore.Web.UI.Sheer;
using Sitecore.Web.UI.HtmlControls;
using Sitecore.StringExtensions;
using System.Web;
namespace Prototype.Commands
{
public class ChangeCountry : WebEditCommand
{
protected Dictionary<string, CountryOption> _countries = new Dictionary<string, CountryOption>
{
{"US", new CountryOption {
ID = "US",
Name = "United States",
Icon = "Flags/32x32/flag_usa.png"
}},
{"CA", new CountryOption {
ID = "CA",
Name = "Canada",
Icon = "Flags/32x32/flag_canada.png"
}},
{"MX", new CountryOption {
ID = "MX",
Name = "Mexico",
Icon = "Flags/32x32/flag_mexico.png"
}},
{"DE", new CountryOption {
ID = "DE",
Name = "Germany",
Icon = "Flags/32x32/flag_germany.png"
}}
};
public override void Execute(Sitecore.Shell.Framework.Commands.CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
if (context.Items.Length == 1)
{
Item item = context.Items[0];
SheerResponse.DisableOutput();
Menu control = new Menu();
//replace with lookup and loop of available values
foreach (var key in _countries.Keys)
{
var country = _countries[key];
string id = country.ID;
string header = country.Name;
string icon = country.Icon;
string click = "prototype:setcountry(country={0})".FormatWith(key);
control.Add(id, header, icon, string.Empty, click, false, string.Empty, MenuItemType.Normal);
}
SheerResponse.EnableOutput();
SheerResponse.ShowPopup("ChangeCountryButton", "below", control);
}
}
public override string GetHeader(Sitecore.Shell.Framework.Commands.CommandContext context, string header)
{
HttpCookie country = HttpContext.Current.Request.Cookies["country"];
if (country != null && _countries.ContainsKey(country.Value))
{
return _countries[country.Value].Name;
}
return base.GetHeader(context, header);
}
public override string GetIcon(Sitecore.Shell.Framework.Commands.CommandContext context, string icon)
{
HttpCookie country = HttpContext.Current.Request.Cookies["country"];
if (country != null && _countries.ContainsKey(country.Value))
{
return _countries[country.Value].Icon;
}
return base.GetIcon(context, icon);
}
protected class CountryOption
{
public string ID { get; set; }
public string Name { get; set; }
public string Icon { get; set; }
}
}
}
Commands.config 또는 포함 파일에서 새 명령을 등록하십시오.
<command name="prototype:changecountry" type="Prototype.Commands.ChangeCountry,Prototype" />
국가 변경 버튼
는 /sitecore/content/Applications/WebEdit/Ribbons/WebEdit/Experience
에 새 청크와 만들기 버튼을 클릭합니다. 이 리본 스트립은 미리보기 모드에서도 참조/복제됩니다.
클릭 필드는 명령의 이름과 일치해야하며, ID 필드 위의 SheerResponse.ShowPopup
전화에서 제공되는 요소 ID와 일치해야합니다 :이 버튼은 다음과 같은 속성을 사용합니다.
SetCountry 명령
다음 메뉴/드롭에있는 항목이 선택 될 때 호출되는 명령입니다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sitecore.Shell.Applications.WebEdit.Commands;
using System.Net;
using Sitecore.Diagnostics;
using Sitecore.Web.UI.Sheer;
using System.Web;
namespace Prototype.Commands
{
public class SetCountry : WebEditCommand
{
public override void Execute(Sitecore.Shell.Framework.Commands.CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
var country = context.Parameters["country"];
Assert.IsNotNullOrEmpty(country, "Country not found");
HttpCookie cookie = new HttpCookie("country", country);
HttpContext.Current.Response.Cookies.Add(cookie);
WebEditCommand.Reload(WebEditCommand.GetUrl());
}
}
}
이 예에서는 선택한 값을 기반으로 쿠키를 설정하고 페이지를 다시로드합니다. 전달 된 값은 ChangeCountry
에있는 메뉴 항목과 연관된 클릭 이벤트를 기반으로합니다. 마찬가지로 구성 할 때 명령 이름은 ChangeCountry
클릭 이벤트에서 사용 된 것과 일치해야합니다.
<command name="prototype:setcountry" type="Prototype.Commands.SetCountry,Prototype" />
- 1. 드롭 다운 메뉴를 표시하는 버튼을 만드는 방법은 무엇입니까?
- 2. UITableView에서 드롭 다운 메뉴를 만드는 방법은 무엇입니까?
- 3. 드롭 다운 메뉴를 만드는 방법은 무엇입니까?
- 4. 이미지가있는 드롭 다운 메뉴를 만드는 방법은 무엇입니까?
- 5. jQuery를 사용하여 드롭 다운 메뉴를 만드는 방법
- 6. jQuery를 사용하여 다중 레벨 드롭 다운 메뉴를 만드는 방법은 무엇입니까?
- 7. CSS를 사용하여 상단에서 고정 드롭 다운 메뉴를 만드는 방법은 무엇입니까?
- 8. 플라밍고 리본 메뉴를 만드는 방법은 무엇입니까?
- 9. Amazon에 표시되는 드롭 다운 메뉴를 만드는 방법은 무엇입니까?
- 10. 드롭 다운 메뉴에서 가로 메뉴를 만드는 방법은 무엇입니까?
- 11. 제목보다 넓은 드롭 다운 메뉴를 만드는 방법은 무엇입니까?
- 12. 드롭 다운 메뉴에서 하위 메뉴를 만드는 방법은 무엇입니까?
- 13. 드롭 다운 메뉴에서 CSS 드롭 다운 메뉴를 만드는 방법
- 14. CSS 드롭 다운 메뉴 드롭 다운 메뉴를 만드는 방법
- 15. CSS로 드롭 다운 메뉴를 만드는 방법
- 16. Delphi XE2에서 리본 갤러리를 만드는 방법은 무엇입니까?
- 17. amazon.com에서 메뉴를 만드는 방법은 무엇입니까?
- 18. WordPress 드롭 다운 메뉴를 만드는 맞춤 CSS
- 19. Jquery 드롭 다운 메뉴를 사용하여 메뉴 숨기기를 지연하는 방법은 무엇입니까?
- 20. 드롭 다운 메뉴를 열고
- 21. 드롭 다운 상자를 만드는 방법은 무엇입니까?
- 22. Android에서 라디오 버튼을 사용하여 하위 메뉴를 만드는 방법은 무엇입니까?
- 23. iPhone 드롭 다운 보이기 버튼을 만드는 방법
- 24. 드롭 다운 메뉴를 만들 때 .hover로 메뉴를 표시하는 방법
- 25. 텍스트가 변경되었을 때 AutoCompleteTextView의 드롭 다운 메뉴를 표시하는 방법은 무엇입니까?
- 26. 드롭 다운 목록을 만드는 방법은 무엇입니까? 구글
- 27. android에서 사용자 정의 드롭 다운 메뉴를 만드는 방법
- 28. 안드로이드는 드롭 다운 메뉴를 만듭니다
- 29. 드롭 다운 메뉴를 채우는 방법
- 30. 드롭 다운 메뉴를 수직으로 변환