Umbarco API for Nodes in C# Options
lpastor
Posted: Thursday, September 11, 2008 2:34:06 PM

Rank: Aficionado

Joined: 8/4/2008
Posts: 111
Location: Serbia
Hi

I new in Umraco but I'm familiar with concept but I need some tips ...

my contents look like


now I want to build a user component on that will be used for navigation trough all pages in the same chapter.

so this user control should be in template of all pages type documents.

my problem is next

how can I found the current page nodeId form Umraco API?

And more importand how to make link on previous and next page (accualy to previous and next node in the same branch).

It have to be user control becouse I will going to have some bussines logic here (like stored some data in DB ect...)

is there any similar solution on forum or some tips or example of code will be great


HELP Anxious





imayat12
Posted: Thursday, September 11, 2008 3:04:32 PM

Rank: Addict

Joined: 7/19/2006
Posts: 670
Location: Preston, UK
lpastor,

You need nodefactory

Code:

umbraco.presentation.nodeFactory.Node.GetCurrent().Id


ps you can get api documentation here

Regards

Ismail

Level 2 certified. If it aint broke dont fix.
lpastor
Posted: Thursday, September 11, 2008 9:08:40 PM

Rank: Aficionado

Joined: 8/4/2008
Posts: 111
Location: Serbia
hi Ismail

yes but how can I found next or previous Node in the same level and make nice URL of it ?

example: on page3 get link to page2 and page4 (see picture above)

thanks


lpastor
Posted: Friday, September 12, 2008 10:27:27 AM

Rank: Aficionado

Joined: 8/4/2008
Posts: 111
Location: Serbia
Any idea ???
cpalm
Posted: Friday, September 12, 2008 1:16:55 PM

Rank: Aficionado

Joined: 7/19/2006
Posts: 165
lpastor wrote:
Any idea ???

It is pretty straightforward

Code:
using umbraco.presentation.nodeFactory;

Node currentNode = Node.GetCurrent();
Node parentNode = currentNode.Parent;
Nodes nodes = parentNode.Children;

foreach (Node node in nodes)
{
    bool isCurrentNode = node.Id == currentNode.Id;
    
    if (isCurrentNode)
    {
        Response.Write("<strong>");
    }

    Response.Write(node.Name);
    Response.Write("<br />");
    
    if (isCurrentNode)
    {
        Response.Write("</strong>");
    }
}


CPalm, www.cpalm.dk
lpastor
Posted: Friday, September 12, 2008 4:03:51 PM

Rank: Aficionado

Joined: 8/4/2008
Posts: 111
Location: Serbia
it is working like a charm :-)

Thanks a lot ...


probably silly question but how can I use that niceUrl (umbraco.library:NiceUrl(@id)) method from API to make a link



imayat12
Posted: Friday, September 12, 2008 5:39:35 PM

Rank: Addict

Joined: 7/19/2006
Posts: 670
Location: Preston, UK


umbraco.library.NiceUrl

Regards

Ismail

Level 2 certified. If it aint broke dont fix.
staunsholm
Posted: Wednesday, September 17, 2008 5:02:18 PM

Rank: Newbie

Joined: 9/2/2008
Posts: 1
Location: Denmark
I tried the above example.

For some reason I get a "System.NullReferenceException: Object reference not set to an instance of an object.".

It is the line of 'Nodes nodes = parentNode.Children;', in other words parentNode is 'null'.

Can anybody tell me how this can happen? I think I must have misunderstood something basic here...

Mkkl.

jonhoye
Posted: Saturday, October 18, 2008 1:34:56 AM
Rank: Newbie

Joined: 9/5/2008
Posts: 9
Location: Chattanooga, TN
For anyone that stumbles here and has the same problem as staunsholm, I think it has to do with the root node returning as null, so if you're trying this from a level 1 node it might not work.

Have a workaround at:

http://forum.umbraco.org/yaf_postsm32556_Can-I-use-NodeFactory-to-get-the-root-directory.aspx#32556
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.