I have a list of "modules" that I want to load depending on what template the current item is based on. This selection needs to be overridable. So I created a module loader component that has a datasource pointing to a folder that contains these modules. I iterate through the children of the folder, pull the RenderingReference and generate a new rendering. Finally I call the mvc.renderRendering
pipeline. This seems to work great, but it does limit me some. The Parameters = ...
line doesn't pull the parameters from the RenderingContext as this is a generic reference to the rendering and not the item's rendering properties.
So my question is, is there a better way to accomplish my overall goal here of loading dynamic items? Or can I get the parameters from my items?
foreach (Item childItem in item.Children)
{
var renderings = childItem.Visualization.GetRenderings(Context.Device, false);
if (renderings.Length > 0)
{
var rendering = new Rendering
{
RenderingItem = renderings[0].RenderingItem,
Item = childItem,
Parameters = new RenderingParameters(renderings[0].RenderingItem.Parameters)
};
var writer = new StringWriter();
var args = new RenderRenderingArgs(rendering, writer);
PipelineService.Get().RunPipeline("mvc.renderRendering", args);
output += writer.ToString();
}
}