Umbraco 如何检查页面或节点(IPPublishedContent)是否使用特定的继承文档类型?
我有一个文档类型页面,它继承自父文档类型页面库 在呈现的页面上,我可以查看文档类型是否等于页面文档类型别名:Umbraco 如何检查页面或节点(IPPublishedContent)是否使用特定的继承文档类型?,umbraco,umbraco7,Umbraco,Umbraco7,我有一个文档类型页面,它继承自父文档类型页面库 在呈现的页面上,我可以查看文档类型是否等于页面文档类型别名: // Where Model is type Umbraco.Web.Models.RenderModel. if (Model.Content.DocumentTypeAlias == "page") { // My current page uses the "page" document type. } 但是如何检查我的IPublishedContent是否继承自页面库?
// Where Model is type Umbraco.Web.Models.RenderModel.
if (Model.Content.DocumentTypeAlias == "page")
{
// My current page uses the "page" document type.
}
但是如何检查我的
IPublishedContent
是否继承自页面库?发现在IPublishedContent
类型上有一种方法:
// Where Model is type Umbraco.Web.Models.RenderModel.
if (Model.Content.IsDocumentType("pageBase", true))
{
// My current page uses the "pageBase" document type.
}
.IsDocumentType()
上接受布尔值的重载称为递归
,它检查您的IPublishedContent
是否是提供的文档类型,或者是从该文档类型派生的
更新:但是!!
如果您的文档类型存储在文件夹中,则使用递归.IsDocumentType()
时会出现错误。此问题已被记录
相反,您可以使用.IsComposedOf()
:
此方法同时检查文档类型组合和继承
此方法不同于递归的
.IsDocumentType()
,因为它只检查继承/组合,而不检查当前文档类型是否为提供的别名。。你能检查一下你的答案是否正确吗?哈哈,我很愿意,但我不得不在接受我自己的答案之前再留一天
// Where Model is type Umbraco.Web.Models.RenderModel.
if (Model.Content.IsComposedOf("pageBase"))
{
// My current page uses the "pageBase" document type.
}