Get DocumentType Object and Node Level From umbraco.presentation.nodeFactory.
Hi All,
I have a umbraco.presentation.nodeFactory.Node and i want to be able to get a DocumentType object from it.. as well as this I'd like to access the level as well.. I'm trying to work out why these attributes aren't exposed in the Node Class.. and the best work around
What I'm essentially trying to do is the following:
I have examine searching a whole pile of nodes.. some of those are nodes used for content holding only (not in a nice layout the user can visit on a page) for example an faq answer.
So in the search results if the search finds content in the faq answer to display, iterate upwards and find the faq page (which is a descendant of a certain document type)
I'm trying to get find if the current node is a descendant of a certain document type (aka a page in a nice layout that users can see) and if so use it's link.. if it isn't then check it's parent and see if it is a descendant of a certain document type. I have a Node object and wanted to access it's DocumentType object... alas instead the work around is converting back to XML and checking that.. is there a better way??
string GetPageUrlForPageNode(Node currentNode) { string result = umbraco.library.NiceUrl(currentNode.Id); var nodeAsXml = umbraco.library.GetXmlNodeById(currentNode.Id.ToString()); var nodeLevel = nodeAsXml.Current.GetAttribute("level",""); var nodeDocType = nodeAsXml.Current.GetAttribute("nodeType",""); if (int.Parse(nodeLevel) > 1) { DocumentType currentNodeDocumentType = new DocumentType(int.Parse(nodeDocType)); while (currentNodeDocumentType != null && currentNodeDocumentType.Text != "Standard Page") { currentNodeDocumentType = (DocumentType)currentNodeDocumentType.Parent; }
if (currentNodeDocumentType != null) { return result; } else { result = GetPageUrlForPageNode(currentNode.Parent); } }
Yes, you can use the "NodeTypeAlias" property from the Node object...
umbraco.presentation.nodeFactory.Node node = umbraco.presentation.nodeFactory.Node.GetCurrent();
umbraco.cms.businesslogic.web.DocumentType docType = umbraco.cms.businesslogic.web.DocumentType.GetByAlias(node.NodeTypeAlias);
// do what you like with the 'docType' object
Get DocumentType Object and Node Level From umbraco.presentation.nodeFactory.
Hi All,
I have a umbraco.presentation.nodeFactory.Node and i want to be able to get a DocumentType object from it.. as well as this I'd like to access the level as well.. I'm trying to work out why these attributes aren't exposed in the Node Class.. and the best work around
Cheers,
Tom
What I'm essentially trying to do is the following:
I have examine searching a whole pile of nodes.. some of those are nodes used for content holding only (not in a nice layout the user can visit on a page) for example an faq answer.
So in the search results if the search finds content in the faq answer to display, iterate upwards and find the faq page (which is a descendant of a certain document type)
I'm trying to get find if the current node is a descendant of a certain document type (aka a page in a nice layout that users can see) and if so use it's link.. if it isn't then check it's parent and see if it is a descendant of a certain document type. I have a Node object and wanted to access it's DocumentType object... alas instead the work around is converting back to XML and checking that.. is there a better way??
string GetPageUrlForPageNode(Node currentNode)
{
string result = umbraco.library.NiceUrl(currentNode.Id);
var nodeAsXml = umbraco.library.GetXmlNodeById(currentNode.Id.ToString());
var nodeLevel = nodeAsXml.Current.GetAttribute("level","");
var nodeDocType = nodeAsXml.Current.GetAttribute("nodeType","");
if (int.Parse(nodeLevel) > 1)
{
DocumentType currentNodeDocumentType = new DocumentType(int.Parse(nodeDocType));
while (currentNodeDocumentType != null && currentNodeDocumentType.Text != "Standard Page")
{
currentNodeDocumentType = (DocumentType)currentNodeDocumentType.Parent;
}
if (currentNodeDocumentType != null)
{
return result;
}
else
{
result = GetPageUrlForPageNode(currentNode.Parent);
}
}
return result;
}
Hi Tom,
Yes, you can use the "NodeTypeAlias" property from the Node object...
Cheers, Lee.
Also found this post useful. Thanks
This post helped me to determine the default template of a DocumentType, which I needed to embed nodes in a page.
is working on a reply...