I'm currently having some issues, while trying to render a sublayout programatically on the server-side. Basically, I want to render a sublayout found on the item myItem, that has a single rendering (sublayout) on it. The criteria is that it should render out correctly for normal mode and Experience Editor mode.
Currently, this is what I've done:
var builder = new StringBuilder();
using (StringWriter writer = new StringWriter(builder))
using (HtmlTextWriter htmlWriter = new HtmlTextWriter(writer))
{
var renderings = myItem.Visualization.GetRenderings(Sitecore.Context.Device, true);
foreach (var rendering in renderings)
{
var renderControl = rendering.GetControl();
rendering.Settings.DataSource = myItem.Paths.FullPath;
renderControl.RenderControl(htmlWriter);
}
}
var output = builder.ToString();
Looking at the output, this is empty. I've also tried just to call the RenderControl()
and output it to a string, which is then set to null
. I should also note, that I do have a PageContext
in the control where this code is executed. I can also verify that I can add the renderControl
as a child to a ASP placeholder control, which then renders out correctly - but only for preview mode, since is doesn't render the control out with support for the Experience Editor.
What am I missing?