Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Guys,
umbraco.presentation.nodeFactory.Node does not have level property. Would you be able to get it doing
umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("level").Value
Regards
Ismail
Hi Ismail,I have just taken a quick look and I would have presumed it would have been properties of GetCurrent() such as:
umbraco.presentation.nodeFactory.Node.GetCurrent().Pathumbraco.presentation.nodeFactory.Node.GetCurrent().Idumbraco.presentation.nodeFactory.Node.GetCurrent().CreateDate
As all of the above examples are attributes in the XML cache along with level, so it is strange that it is missing.
Warren :)
Doesn't look like it.
You could use split path on the comma, and count how many levels it is?
umbraco.presentation.nodeFactory.Node.GetCurrent().Path.Split(',').LengthMatt
Matt
Warren,
Yup thats what i thought it should be there anyhow got round it i did
var nodeAsXml = umbraco.library.GetXmlNodeById(CurrentNode.Id.ToString()); var nodeLevel = nodeAsXml.Current.GetAttribute("level", "");
How strange that Level is missing as a property in the Node class.
I'd go with Matt's suggestion of splitting the Path and getting the count/length.
If Split isn't cool enough, you could always use a bit of Linq?
umbraco.presentation.nodeFactory.Node.GetCurrent().Path.ToCharArray().Count(x => x == ',');
Interesting alternatives on StackOverflow... http://stackoverflow.com/questions/541954/how-would-you-count-occurences-of-a-string-within-a-string-c
Seems the foreach is fastest! ;-)
string path = umbraco.presentation.nodeFactory.Node.GetCurrent().Path; int count = 0; foreach (char c in path) if (c == ',') count++;
Anyway, we're talking milliseconds here... still interesting to a geek like me! ;-)
Cheers, Lee.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Level property from Node
Guys,
umbraco.presentation.nodeFactory.Node does not have level property. Would you be able to get it doing
Regards
Ismail
Hi Ismail,
I have just taken a quick look and I would have presumed it would have been properties of GetCurrent() such as:
As all of the above examples are attributes in the XML cache along with level, so it is strange that it is missing.
Warren :)
Doesn't look like it.
You could use split path on the comma, and count how many levels it is?
Warren,
Yup thats what i thought it should be there anyhow got round it i did
Regards
Ismail
How strange that Level is missing as a property in the Node class.
I'd go with Matt's suggestion of splitting the Path and getting the count/length.
If Split isn't cool enough, you could always use a bit of Linq?
Matt
Interesting alternatives on StackOverflow... http://stackoverflow.com/questions/541954/how-would-you-count-occurences-of-a-string-within-a-string-c
Seems the foreach is fastest! ;-)
Anyway, we're talking milliseconds here... still interesting to a geek like me! ;-)
Cheers, Lee.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.