No parenthesis on the "GetCurrent" portion of the code. The rest of the code shows a sample of updating, saving and publishing the new content.
' Use this to open the document
Document document = new Document(Node.GetCurrent.ID);
' Update and save a property value
Document.getProperty("myProp").Value = myFormObject.Value;
Document.Save();
' Publish the document as the root administrator
Document.Publish(New umbraco.businesslogic.user(0));
' Update the umbraco cache
umbraco.library.UpdateDocumentCache(Document.ID);
hmm I'm bothered by the fact that there's three perfectly valid yet completely different ways of accessing the ID of the current page (and I do believe there's at least one more :P).
For the record, going forward the recommended way in which you would be getting it is via the UmbracoContext.Current object. I'd really like only a single one to maintain.
Hendy - the assumption (from Mikael's reference above) is that his code has already loaded the unpublished content, though I am not sure where it comes from. By using the API rather than the umbraco core, it is possible to open and read the node regardless of it's published state and still maintain versioning.
Slace - I think that there might be a problem with existing XSLT functions not being able to reference umbraco.library.pageid as a method of obtaining the current node id. Certainly a consideration before the framework is updated as that could render items developed using that current "best practice" obsolete.
Chris - I'm pretty sure that you'll find that the current page ID is passed into each XSLT OOB, I think it's in the currentId parameter (can't remember rightly, I dont' really use XSLT, I prefer .NET)
How to get current document.
If i use the node factory i can do something like node.getcurrent to get the current node. How can i get the current document using the document API ?
There is no document.getcurrent method or similar, as far as i cab see.
I need to use the document API because this code works with unpublished nodes.
Thanks
Mikael
Ahh, i think i found it myself:
int currentNodeId = umbraco.presentation.UmbracoContext.Current.PageId.Value;
This should work with unpublished nodes right ?
Mikael
how about: Document document = new Document(Node.GetCurrent().Id);
No parenthesis on the "GetCurrent" portion of the code. The rest of the code shows a sample of updating, saving and publishing the new content.
Hi Chris,
umbraco.presentation.nodeFactroy.Node.GetCurrent() is a method tho ?
re-reading the original question, I'm not clear on now the current node can ever be an unpublished one ?
hmm I'm bothered by the fact that there's three perfectly valid yet completely different ways of accessing the ID of the current page (and I do believe there's at least one more :P).
For the record, going forward the recommended way in which you would be getting it is via the UmbracoContext.Current object. I'd really like only a single one to maintain.
Hendy - the assumption (from Mikael's reference above) is that his code has already loaded the unpublished content, though I am not sure where it comes from. By using the API rather than the umbraco core, it is possible to open and read the node regardless of it's published state and still maintain versioning.
Slace - I think that there might be a problem with existing XSLT functions not being able to reference umbraco.library.pageid as a method of obtaining the current node id. Certainly a consideration before the framework is updated as that could render items developed using that current "best practice" obsolete.
Chris - I'm pretty sure that you'll find that the current page ID is passed into each XSLT OOB, I think it's in the currentId parameter (can't remember rightly, I dont' really use XSLT, I prefer .NET)
Erm I am not sure if I am following entirely correctly here, but in XSLT to get the currentPage (node) ID is fairly simple:
That's it, I knew it was passed into an XSLT somehow :P
Is that not a function of the declaration of umbraco.library as an XML namespace at the root of the XSLT document though?
xmlns:umbraco.library="urn:umbraco.library"
is working on a reply...