I'm kinda new to using user controls with Umbraco and usually use XSLT.
I have a user control that I need to return all the child nodes and sometimes also grandchildren nodes for a specifc node of which I know the ID. I would prefer to add these to an array using a loop, but I'm not really sure how to use the API to get the data.
I may obsolete that method and push it into the UmbracoContext, there's so many ways to do this stuff that I'd like to see it centralized around the context
I have referenced umbraco.dll and receive the commands like umbraco.presentation etc then when I get to the current part it cannot find current. Do I need one of those <%@ register things at the top of the page? At the moment I have <#%@ assembly="umbraco" %> but doesn't change anything.
The current part of what, the UmbracoContext? UmbracoContext was added in Umbraco 4.0 and is in the umbraco.presentation namespace in the umbraco.dll assembly.
Maybe it'd help if you posted your code thus far and we can let you know where you're going wrong
List all child nodes using API?
Hi everyone,
I'm kinda new to using user controls with Umbraco and usually use XSLT.
I have a user control that I need to return all the child nodes and sometimes also grandchildren nodes for a specifc node of which I know the ID. I would prefer to add these to an array using a loop, but I'm not really sure how to use the API to get the data.
I'm using Umbraco 4 and coding in C#.
Can anyone point me in the right direction?
Thank you very much
Shufflemoomin
Hi,
It's no different from using the umbraco library methods from within xslt...
Even in your user control, you could for example use umbraco.library.GetXmlNodeByXPath(). Just need to know what xpath query to use and you're set.
For listing children of a specific node, you'd probably use //node [@id = id]/node or //node [@id = id]/node
For listing grandchildren of a specific node, you'd //node [@id = id]//node or //node [@id = id]//node
Hope this helps.
Regards,
/Dirk
Hi using the pure API and no XSLT you would do the following.
to get the children on your known node you would do the following (this is the long hand way so you can see all the parts easily
if you were then going to bind this to a say repeater just bind as usual
then in the code fron on the repeater to get the properties of the node you would do the following
Hope that helps!
Peter
If you want the ID of the current page to pass to the constructor you can get it via the UmbracoContext:
And if you want to get the current node for the current page:
I may obsolete that method and push it into the UmbracoContext, there's so many ways to do this stuff that I'd like to see it centralized around the context
I have referenced umbraco.dll and receive the commands like umbraco.presentation etc then when I get to the current part it cannot find current. Do I need one of those <%@ register things at the top of the page? At the moment I have <#%@ assembly="umbraco" %> but doesn't change anything.
Thanks
The current part of what, the UmbracoContext? UmbracoContext was added in Umbraco 4.0 and is in the umbraco.presentation namespace in the umbraco.dll assembly.
Maybe it'd help if you posted your code thus far and we can let you know where you're going wrong
On the example given by Peter above it should read:
I.e. the "Children" for node.Children should be a capital C...
Once I changed that, it did exactly what I needed, thanks Peter :)
Cheers,
Chris
How can i chagne childrenNodes to datatable in following code snipet.
umbraco.presentation.nodeFactory.Node node = new umbraco.presentation.nodeFactory.Node(1071);
umbraco.presentation.nodeFactory.Nodes childrenNodes = node.Children;
Thanks
JIgar
Duplicate question from JIgar. See the Datatable snippet on this post
is working on a reply...