Odd. Which version of Umbraco are you running? I've copied that from my Visual Studio where I've double checked that Node actually has a property called 'Level', I'm on the latest Umbraco version. No custom extension.
In any case, should you not have the Level property your solution is definitely quite alright as well, depending on how it is implemented internally it might even work faster your way, but I'm out of my depths here I'm afraid...
and here is the Node factory and there is no Level Property.
What version you have ?
namespace umbraco.presentation.nodeFactory { [Serializable] [XmlType(Namespace = "http://umbraco.org/webservices/")] public class Node { public Node(); public Node(int NodeId); public Node(XmlNode NodeXmlNode); public Node(int NodeId, bool forcePublishedXml); public Node(XmlNode NodeXmlNode, bool DisableInitializing);
public Nodes Children { get; } public DateTime CreateDate { get; } public int CreatorID { get; } public string CreatorName { get; } public int Id { get; } public string Name { get; } public string NiceUrl { get; } public string NodeTypeAlias { get; } public Node Parent { get; } public string Path { get; } public Properties Properties { get; } public int SortOrder { get; } public int template { get; } public DateTime UpdateDate { get; } public string Url { get; } public Guid Version { get; } public int WriterID { get; } public string WriterName { get; }
public DataTable ChildrenAsTable(); public DataTable ChildrenAsTable(string nodeTypeAliasFilter); public static Node GetCurrent(); public Property GetProperty(string Alias); } }
Ah, that explains it. I've got 4.6.1, and I've looked at the source code to find that umbraco.presentation.nodeFactory.Node is now obsolete and that umbraco.NodeFactory.Node should be used instead, which has the Level property (and you are absolutely right, the umbraco.presentation.nodeFactory.Node class doesn't have a Level property as outlined in your post above). So I guess if you don't upgrade to 4.6.1 your best bet is your initial solution!
If I understand you correctly you don't necessarily need to use the @level attribute to achieve what you want to do. If you just want to output links to the siblings of the current node you could do something like
You can use the level as well, yet the outcome is different since you are also displaying nodes which are at the same level, yet have different parents and are therefore not siblings (just not sure if this is what you want to do):
<xsl:for-each select="$currentPage/ancestor-or-self::root[@isDoc]/descendant-or-self::*[@isDoc and @level = $currentPage/@level]">
Get Current Node Level in .NET Code
Hi,
I am trying to get a level like in XSLT @level in current node.
Is this the only way to do it.
var nodeAsXml = umbraco.library.GetXmlNodeById(currentNode.Id.ToString());
var nodeLevel = nodeAsXml.Current.GetAttribute("level","");
Can I get it directly from UmbracoNode ?
Thanks
Hi Kruniawan,
try
that should do the trick! :)
Cheers, Sascha
Hi Sasha,
Node doesn't have property Level.
Is that different from yours ? or you create your extension method ?
Odd. Which version of Umbraco are you running? I've copied that from my Visual Studio where I've double checked that Node actually has a property called 'Level', I'm on the latest Umbraco version. No custom extension.
In any case, should you not have the Level property your solution is definitely quite alright as well, depending on how it is implemented internally it might even work faster your way, but I'm out of my depths here I'm afraid...
It's weird coz I use version v4.5.2
and here is the Node factory and there is no Level Property.
What version you have ?
namespace umbraco.presentation.nodeFactory
{
[Serializable]
[XmlType(Namespace = "http://umbraco.org/webservices/")]
public class Node
{
public Node();
public Node(int NodeId);
public Node(XmlNode NodeXmlNode);
public Node(int NodeId, bool forcePublishedXml);
public Node(XmlNode NodeXmlNode, bool DisableInitializing);
public Nodes Children { get; }
public DateTime CreateDate { get; }
public int CreatorID { get; }
public string CreatorName { get; }
public int Id { get; }
public string Name { get; }
public string NiceUrl { get; }
public string NodeTypeAlias { get; }
public Node Parent { get; }
public string Path { get; }
public Properties Properties { get; }
public int SortOrder { get; }
public int template { get; }
public DateTime UpdateDate { get; }
public string Url { get; }
public Guid Version { get; }
public int WriterID { get; }
public string WriterName { get; }
public DataTable ChildrenAsTable();
public DataTable ChildrenAsTable(string nodeTypeAliasFilter);
public static Node GetCurrent();
public Property GetProperty(string Alias);
}
}
Ah, that explains it. I've got 4.6.1, and I've looked at the source code to find that umbraco.presentation.nodeFactory.Node is now obsolete and that umbraco.NodeFactory.Node should be used instead, which has the Level property (and you are absolutely right, the umbraco.presentation.nodeFactory.Node class doesn't have a Level property as outlined in your post above). So I guess if you don't upgrade to 4.6.1 your best bet is your initial solution!
Cheers,
Sascha
Hi,
I need to find current level by using xslt.
How can I do this?
Thanks.
level is stored in atrribute of it's node in xml. so you can simple take it using @level
I have an xslt like this :
<xsl:param name="currentPage"/>
<xsl:variable name="level" select="3"/>
<xsl:template match="/">
<ul>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1' and @id != $currentPage/@id]">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
a>
li>
xsl:for-each>
ul>
xsl:template>
I want to list all nodes except current node in current level, how can I use current level in this situation.
<xsl:variable name="currentLevel" select="@level"/>
[@level=$currentLevel]doesn't work.
Thanks.
Hi Seyfullah,
If I understand you correctly you don't necessarily need to use the @level attribute to achieve what you want to do. If you just want to output links to the siblings of the current node you could do something like
<xsl:variable name="parentOfCurrentPage" select="$currentPage/parent::*[@isDoc]" />
<xsl:for-each select="$parentOfCurrentPage/*[@isDoc and @id != $currentPage/@id]">
<a href="{umbraco.library:NiceUrl(current()/@id)}"><xsl:value-of select="current()/@nodeName" /></a>
</xsl:for-each>
You can use the level as well, yet the outcome is different since you are also displaying nodes which are at the same level, yet have different parents and are therefore not siblings (just not sure if this is what you want to do):
<xsl:for-each select="$currentPage/ancestor-or-self::root[@isDoc]/descendant-or-self::*[@isDoc and @level = $currentPage/@level]">
{{same as above}}
Hope that helps,
Sascha
First one works great for me.
Thanks :)
I'm using this one:
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:value-of select="$currentPage/@level"/>
And it works fine (Umbraco 4.7.1 and 4.9)
is working on a reply...