Sitecore渲染,如何获取渲染定义项
本文关键字:定义 获取 渲染 何获取 Sitecore | 更新日期: 2023-09-27 18:26:24
我们使用混合剃须刀引擎在Sitecore中创建组件。我需要获得渲染定义id,但我无法获得它。这是我们的baseComponent
类,它继承自Sitecore.Web.UI.WebControl
protected override void DoRender(HtmlTextWriter output)
{
string razorpath = RazorPath;
Model = GetViewModel();
var itemId = ID; //renderingID || getitem() also not working
HttpContext.Current.Response.Write(itemId);
Guid itemGuid;
if (Guid.TryParse(itemId, out itemGuid))
{
var webControl = ContentStore.GetItem<WebControl>(itemId);
if (webControl != null && string.IsNullOrEmpty(webControl.View))
razorpath = webControl.View.Replace("/WebControls", "");
}
var renderedContent = TemplateExpander.ExpandTemplate(razorpath, Model);
output.Write(renderedContent);
}
不完全确定你想要的是什么,但由于你继承了Sitecore.Web.UI.WebControl,你想要的可能是这样的东西:
var p = Parent as Sublayout;
var rId = p.RenderingID;