I'm quite new to XSLT and Umbraco and I want to create a page, taking as input the URL of a node.
This page should display some properties of the node passed as input.
It is quite esay to get a node knowing its ID, but I couldn't find a "GetNodeByURL" function.
Umbraco should do it whenever someone is asking for a node using alternative link. But I can't find how.
If using xslt, try umbraco.library:GetXmlByXPath() which takes a xpath string expression making it possible to query the docs using the urlName.
[quote]
Umbraco should do it whenever someone is asking for a node using alternative link.[/quote]
If someone requests a page using an alternative link, all page info (for the current node) is still available through the $currentPage parameter
By "Umbraco should do it whenever someone is asking for a node using alternative link.", I mean that, in your browser, when you type the address of a page of a website using Umbraco, Umbraco will have to retreive the node ID from the address you've typed. And I am wondering if we can access to the functionnality within a macro.
umbraco is responsible for getting the correct page and then makes the current page (node) available through xslt using the $currentPage parameter which can be found on any template to choose from the dropdown when creating an xslt file. In that case, the id of the page is available using:
If, instead, you need the id in a user control, then use Node.GetCurrent().Id in the c# code.
Imagine I have a page addressed by http://www.myumbraco-website.com/usefulPage
This page takes one argument NodeToExamine, which is the URL of an other node, in the same website. So I call it by http://www.myumbraco-website.com/usefulPage?NodeToExamine=www.my_umbraco-website.com/arepository/nodetoBeExamined
Then, in the usefulPage rendering ( using xslt), I want to display, say, the date of creation of the node "arepository/nodetoBeExamined", of which I only know the URL and not the ID.
But I don't want the rendering of the node "arepository/nodetoBeExamined", I only want to have access to its properties.
In that case, I'd make sure not to have the full address but only the '/arepository/nodetoBeExamined' part, and start querying the umbraco xml content for a corresponding node. It'll be a rather nasty xpath expression as you'll need to split the url in parts and build up the complete xpath expression.
Best method to find out how to build the xpath expression is to browse a page which doesn't exists in the umbraco backend, you'll get an idea of what xpath query is build, you'll need something similar...
Still, IMHO, this is not the best solution. I'd still make the node id available instead of the url (which can become ugly with all those slashes...). Again, up to you to decide...
No, I would prefer having the names of the nodes instead of a non-meaning-anything number. And, I will give the name of the node to a third party, so they can include a part of my work in their website. As a consequence, I would prefer having a stable name instead of a a automaticly-incrementing number to give them. I don't know what will happen in the future: if I have to remove the node and recreate it, the number will change, even if the name is the same.
You could add both. The url for display the nodeid to query. With regards to moving deleting you will also have this issue with urls becuase the url is generated according to its path / name so if that changes the url will also change.
how to get node ID from URL
Hi everyone.
I'm quite new to XSLT and Umbraco and I want to create a page, taking as input the URL of a node.
This page should display some properties of the node passed as input.
It is quite esay to get a node knowing its ID, but I couldn't find a "GetNodeByURL" function.
Umbraco should do it whenever someone is asking for a node using alternative link. But I can't find how.
Thanks
Hi,
If using xslt, try umbraco.library:GetXmlByXPath() which takes a xpath string expression making it possible to query the docs using the urlName.
[quote]
Umbraco should do it whenever someone is asking for a node using alternative link.[/quote]
If someone requests a page using an alternative link, all page info (for the current node) is still available through the $currentPage parameter
Or did misunderstand that last question?
Regards,
/Dirk
Thanks Dirk
I forgot to mention that I'm using Umbraco 3.
By "Umbraco should do it whenever someone is asking for a node using alternative link.", I mean that, in your browser, when you type the address of a page of a website using Umbraco, Umbraco will have to retreive the node ID from the address you've typed. And I am wondering if we can access to the functionnality within a macro.
Hi,
umbraco is responsible for getting the correct page and then makes the current page (node) available through xslt using the $currentPage parameter which can be found on any template to choose from the dropdown when creating an xslt file. In that case, the id of the page is available using:
If, instead, you need the id in a user control, then use Node.GetCurrent().Id in the c# code.
Oh, btw, umbraco version does not matter here.
Hope this helps.
Regards,
/Dirk
I think you misunderstood me:
Imagine I have a page addressed by http://www.myumbraco-website.com/usefulPage
This page takes one argument NodeToExamine, which is the URL of an other node, in the same website. So I call it by
http://www.myumbraco-website.com/usefulPage?NodeToExamine=www.my_umbraco-website.com/arepository/nodetoBeExamined
Then, in the usefulPage rendering ( using xslt), I want to display, say, the date of creation of the node "arepository/nodetoBeExamined", of which I only know the URL and not the ID.
But I don't want the rendering of the node "arepository/nodetoBeExamined", I only want to have access to its properties.
Is that clearer?
jdelagoutte,
Where you build the link http://www.myumbraco-website.com/usefulPage?NodeToExamine=www.myumbraco-website.com/arepository/nodetoBeExamined could not do
http://www.my_umbraco-website.com/usefulPage?NodeToExamine=1066
or whatever id then in your target in the macro you can do
and then write out whatever properties.
Regards
Ismail
Ok,
In that case, I'd make sure not to have the full address but only the '/arepository/nodetoBeExamined' part, and start querying the umbraco xml content for a corresponding node. It'll be a rather nasty xpath expression as you'll need to split the url in parts and build up the complete xpath expression.
Best method to find out how to build the xpath expression is to browse a page which doesn't exists in the umbraco backend, you'll get an idea of what xpath query is build, you'll need something similar...
http://www.my_umbraco-website.com/whatever/here-we-go/again.aspx
Still, IMHO, this is not the best solution. I'd still make the node id available instead of the url (which can become ugly with all those slashes...). Again, up to you to decide...
Regards,
/Dirk
Hi imayat12,
No, I would prefer having the names of the nodes instead of a non-meaning-anything number. And, I will give the name of the node to a third party, so they can include a part of my work in their website. As a consequence, I would prefer having a stable name instead of a a automaticly-incrementing number to give them. I don't know what will happen in the future: if I have to remove the node and recreate it, the number will change, even if the name is the same.
But thanks anyway
jdelagoutte,
You could add both. The url for display the nodeid to query. With regards to moving deleting you will also have this issue with urls becuase the url is generated according to its path / name so if that changes the url will also change.
Regards
Ismail
So, I solved it :
I created a alternative template for this type of document I want to examine :
[code]
is working on a reply...