我正在研究后端模块,所以Node.GetCurrent()不是一个选择.我需要找到一种方法来调用类似的东西Node currentNode = new Node(parentNodeId);并获取网站的根节点.我在XSLT中看过样本,但C#没有.有谁知道我怎么能做到这一点?
即使只是获取根节点的ID,我也可以调用new Node()它.
小智 7
Umbraco 7的更新(也可以在早期版本中使用)
@{
var siteroot = CurrentPage.AncestorOrSelf(1);
}
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请查看文档 - > http://our.umbraco.org/Documentation/Reference/Querying/DynamicNode/Collections
Umbraco 6+更新
public static IPublishedContent GetRootNode()
{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var rootNode = umbracoHelper.TypedContentSingleAtXPath("//root"));
return rootNode;
}
Run Code Online (Sandbox Code Playgroud)
这只是一个文档类型别名,并使用当前的Umbraco上下文将根节点查找为IPublishedContent.UmbracoHelper也为您提供了很多选择.