Sometime when we work with Component presentation, we might come up with the scenario to have customized RenderComponentPresentation, when we deal with Area/View or splitting view into more organized structure. We can fetch and send the area from the Template.
Currently DD4T doesn’t allow injecting the ComponentPresentationRenderer, instead it allows us to write our own renderer and call it along with RenderComponentPresentation as below
The custom ComponentPresenationRenderer can be created based on the scenario, so when we use the area, we could have the custom ComponentPresentation as below
SDL Reference implementation, customized Renderer beautifully and implemented the Renderor to use Area view concept.
Currently DD4T doesn’t allow injecting the ComponentPresentationRenderer, instead it allows us to write our own renderer and call it along with RenderComponentPresentation as below
The custom ComponentPresenationRenderer can be created based on the scenario, so when we use the area, we could have the custom ComponentPresentation as below
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static MvcHtmlString RenderComponentPresentation(IComponentPresentation cp, HtmlHelper htmlHelper) | |
{ | |
string controller = ConfigurationHelper.ComponentPresentationController; | |
string action = ConfigurationHelper.ComponentPresentationAction; | |
string area = string.Empty; | |
if (cp.ComponentTemplate.MetadataFields != null && cp.ComponentTemplate.MetadataFields.ContainsKey("controller")) | |
{ | |
controller = cp.ComponentTemplate.MetadataFields["controller"].Value; | |
} | |
if (cp.ComponentTemplate.MetadataFields != null && cp.ComponentTemplate.MetadataFields.ContainsKey("action")) | |
{ | |
action = cp.ComponentTemplate.MetadataFields["action"].Value; | |
} | |
if (cp.ComponentTemplate.MetadataFields != null && cp.ComponentTemplate.MetadataFields.ContainsKey("area")) | |
{ | |
area = cp.ComponentTemplate.MetadataFields["area"].Value; | |
} | |
MvcHtmlString result = htmlHelper.Action(action, controller, new { componentPresentation = ((ComponentPresentation)cp), area = area }); | |
return result; | |
} |
0 comments:
Post a Comment