public Task RenderComponentAsync(RenderingParameter component, RenderingParameter skin, RenderingParameter dataVariation, object model, RenderingContext context) { var mvcContext = context as MvcRenderingContext; if (mvcContext == null) { throw new InvalidOperationException("MvcNitroTemplateHandler can only be used inside a Mvc application."); } new HtmlHelper(mvcContext.ViewContext, mvcContext.ViewDataContainer).RenderAction("Index", component.Value); return(Task.FromResult(false)); }
public void RenderComponent(RenderingParameter component, RenderingParameter skin, RenderingParameter dataVariation, object model, RenderingContext context) { const string thisIdentifier = "this"; var mvcContext = context as MvcRenderingContext; if (mvcContext == null) { throw new InvalidOperationException("MvcNitroTemplateHandler can only be used inside a Mvc application."); } //todo: get sub model -> and then call renderpartial if (string.IsNullOrEmpty(dataVariation.Value)) { dataVariation.Value = component.Value; } var propertyName = CleanName(dataVariation.Value); object subModel = null; if (dataVariation.Value.Equals(thisIdentifier)) { subModel = model; } var modelFound = false; if (subModel == null) { modelFound = GetValueFromObjectHierarchically(model, propertyName, out subModel); } if (subModel != null && !(subModel is string)) { var componentIdBySkin = GetComponentId(component.Value, skin.Value); RenderPartial(componentIdBySkin, subModel, context); return; } new HtmlHelper(mvcContext.ViewContext, mvcContext.ViewDataContainer).RenderAction("Index", component.Value); }
private bool AggregateRenderingParameter(RenderingParameter renderingParameter, object model) { if (renderingParameter == null) { return(false); } if (!renderingParameter.IsDynamic) { return(false); } var propertyName = CleanName(renderingParameter.Value); object dynamicName; if (GetValueFromObjectHierarchically(model, propertyName, out dynamicName) && dynamicName is string) { renderingParameter.Value = dynamicName.ToString(); return(true); } return(false); }
public void RenderComponent(RenderingParameter component, RenderingParameter skin, RenderingParameter dataVariation, object model, RenderingContext context) { var requestContext = PageContext.Current.RequestContext; var savedSkin = requestContext.RouteData.Values["skin"]; var savedModel = requestContext.RouteData.Values["model"]; var savedDataVariation = requestContext.RouteData.Values["dataVariation"]; try { // Try to get values from model AggregateRenderingParameter(component, model); AggregateRenderingParameter(skin, model); if (string.IsNullOrEmpty(dataVariation.Value)) { dataVariation.Value = component.Value; } var propertyName = CleanName(dataVariation.Value); object subModel = null; if (dataVariation.Value.Equals(ThisIdentifier)) { subModel = model; } var modelFound = false; if (subModel == null) { modelFound = GetValueFromObjectHierarchically(model, propertyName, out subModel); } if (subModel != null && !(subModel is string)) { var componentIdBySkin = GetComponentId(component.Value, skin.Value); RenderPartial(componentIdBySkin, subModel, context); return; } if (modelFound && subModel == null) { Log.Error($"Property {propertyName} of model {model.GetType()} is null.", this); return; } var htmlHelper = CreateHtmlHelper(context); var parts = component.Value.Split('/'); var componentName = parts[parts.Length - 1]; var cleanComponentName = CleanName(componentName); var renderingId = _renderingRepository.GetRenderingId(cleanComponentName); requestContext.RouteData.Values["skin"] = skin.Value ?? string.Empty; requestContext.RouteData.Values["dataVariation"] = dataVariation.Value ?? string.Empty; if (renderingId != null) { // TODO: Cache! context.Writer.Write(htmlHelper.Sitecore() .Rendering(renderingId)); } else { var controller = CleanControllerName(componentName); context.Writer.Write(htmlHelper.Sitecore().Controller(controller)); Log.Warn($"Controller {controller} gets directly called by NitroNet. " + $"Consider to create a rendering with name \"{cleanComponentName}\" in order to let the controller be called by the Sitecore rendering pipeline. " + $"Component: {component.Value}, Skin: {skin.Value}, Data: {dataVariation.Value}", this); } } finally { requestContext.RouteData.Values["skin"] = savedSkin; requestContext.RouteData.Values["dataVariation"] = savedDataVariation; requestContext.RouteData.Values["model"] = savedModel; } }