public void RenderPlaceholder(object model, string key, string index, RenderingContext context) { var htmlHelper = CreateHtmlHelper(context); #if SC8 var dynamicKey = key; if (!string.IsNullOrEmpty(index)) { dynamicKey = key + "_" + index; } context.Writer.Write(htmlHelper.Sitecore().DynamicPlaceholder(dynamicKey)); #else if (string.IsNullOrEmpty(index)) { context.Writer.Write(htmlHelper.Sitecore().Placeholder(key)); return; } if (int.TryParse(index, out var parsedIntIndex)) { context.Writer.Write(htmlHelper.Sitecore().DynamicPlaceholder(key, 1, 0, parsedIntIndex)); return; } if (ID.TryParse(index, out var parsedIdIndex)) { context.Writer.Write(htmlHelper.Sitecore().DynamicPlaceholder(key, parsedIdIndex)); return; } throw new ArgumentException($"'Index' attribute of {{placeholder}} helper needs to be an integer or Sitecore.Data.ID string. The chosen index is '{index}'"); #endif }
public Task RenderLabelAsync(string key, RenderingContext context) { var label = SC.Globalization.Translate.Text(key); context.Writer.Write(label); return(Task.FromResult(true)); }
private static MvcRenderingContext GetMvcContext(RenderingContext context) { var mvcContext = context as MvcRenderingContext; if (mvcContext == null) { throw new InvalidOperationException("SitecoreMvcNitroTemplateHandler can only be used inside a Mvc application."); } return(mvcContext); }
public void RenderPlaceholder(object model, string key, string index, RenderingContext context) { var htmlHelper = CreateHtmlHelper(context); var dynamicKey = key; if (!string.IsNullOrEmpty(index)) { dynamicKey = key + "_" + index; } context.Writer.Write(htmlHelper.Sitecore().DynamicPlaceholder(dynamicKey)); }
public void Render(object model, RenderingContext context) { using (ContextService.Get().Push(context)) { var renderingModel = model as RenderingModel; if (renderingModel != null) { var renderingParameters = renderingModel.Rendering.Parameters.ToDictionary(k => k.Key, k => k.Value); _adaptee.Render(JObject.FromObject(renderingParameters), context); } else { _adaptee.Render(model, context); } } }
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; } }
public Task RenderPlaceholderAsync(object model, string key, string index, RenderingContext context) { throw new NotImplementedException(); }
private static HtmlHelper CreateHtmlHelper(RenderingContext context) { return(CreateHtmlHelper(GetMvcContext(context))); }
public void RenderPartial(string template, object model, RenderingContext context) { CreateHtmlHelper(context).RenderPartial(template, model); }
public Task RenderPartialAsync(string template, object model, RenderingContext context) { throw new NotImplementedException(); }
public void RenderLabel(string key, RenderingContext context) { var label = SC.Globalization.Translate.Text(key); context.Writer.Write(label); }
public Task RenderAsync(object model, RenderingContext context) { Render(model, context); return(Task.FromResult(true)); }