Skip to content

Instantly share code, notes, and snippets.

@hishaamn
Created September 19, 2025 12:04
Show Gist options
  • Select an option

  • Save hishaamn/d42d1cd28f7c91c95dd7d5d4096e9715 to your computer and use it in GitHub Desktop.

Select an option

Save hishaamn/d42d1cd28f7c91c95dd7d5d4096e9715 to your computer and use it in GitHub Desktop.
private void RenderControl(Item child, StringBuilder commandsBuilder)
{
var header = child["Header"];
if (string.IsNullOrEmpty(header)) header = child.DisplayName;
var icon = child["Icon"] ?? child["__Icon"];
var click = child["Click"];
commandsBuilder.AppendLine("<div style='margin:6px 0;'>");
try
{
var largeButton = new LargeButton
{
ID = "lb_" + child.ID.ToShortID(),
Header = header,
Icon = icon ?? string.Empty,
Command = click ?? string.Empty,
BorderWidth = 100,
CssClass = "scxm-overlay-largebutton"
};
using (var sw = new StringWriter())
using (var htw = new HtmlTextWriter(sw))
{
largeButton.RenderControl(htw);
commandsBuilder.AppendLine(sw.ToString());
}
}
catch (Exception ex)
{
Log.Warn($"SlidePanelInjector: Failed to render LargeButton for item {child.Paths.FullPath}. Falling back to HTML button.", ex, this);
var safeClick = string.IsNullOrEmpty(click)
? ""
: $"javascript:scForm.postEvent(this,event,'{HttpUtility.JavaScriptStringEncode(click)}')";
commandsBuilder.AppendLine($@"
<div class='panel-command-fallback' style='margin:6px 0;'>
<button style='width:100%;padding:8px;text-align:left;' onclick=""{safeClick}"">
{(string.IsNullOrEmpty(icon) ? "" : $"<img src='/sitecore/shell/themes/standard/{icon}' style='width:16px;height:16px;margin-right:8px;vertical-align:middle;' />")}
<span style='vertical-align:middle;'>{System.Web.HttpUtility.HtmlEncode(header)}</span>
</button>
</div>");
}
commandsBuilder.AppendLine("</div>");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment