MNTP Xpath $current, $parent point to different node when creating a new node vs editing an existing node
Not sure why I've missed it until now, but I would just like a verification from someone that has already experienced it. I noticed that the context-aware placeholders $current and $parent point to the parent node (and parent-of-parent node respectively) when the node being created is new (i.e. hasn't been published yet).
On the other hand, as soon as the node is published, they point to their respective anticipated locations.
I can guess that happens on creation of a new node because since the node is not published yet, the only close (published) point of reference is its parent - but I'd really like to hear it from someone who's had the same issue. Is that what's supposed to be happening?
I noticed that there have been some references to issues with those placeholders for earlier Umbraco versions but those regarded errors, not behaviour.
Yes, that's "correct" - not really anything to do about it; as you've noticed, it's because the newly created node isn't published and thus not available in the XML tree.
Good to know! I was afraid I was missing something somewhere.
I'll describe the issue I faced below, and how I solved it, hoping it'll help others (also hoping it won't confuse them more :) )
The solution I generally found effective in case, for example, I needed to point to the node's parent by doctype is that I could use
$current/ancestor-or-self::xxx
instead of
$parent
(assuming that $parent IS of doctype xxx) or
$parent/xxx
or
$parent/../../..//xxx
or whatever similar
(or any other path including $parent, where xxx is the doctype) to point to to a specific node type upwards in the hierarchy regardless of where $current points to my original node (if it is published) or its parent (if it's new).
For example, I've got a "Blog" folder and under it I've got the following structure:
Blog (doctype: pageBlogList)
-- Posts
---- Post 1
---- Post 2
---- etc.
-- Categories
---- Category 1
---- Category 2
---- etc.
-- Authors (doctype: folderAuthors)
---- Author 1
---- Author 2
---- etc.
(I only mentioned the doctypes for the nodes I'm going to use below. )
When I create a new "Post", I have pickers with which I can select an author and one or more categories. The pickers point to the "Categories" and "Authors" documents respectively, each one having its own doctype.
So the xpath query
$parent/../folderAuthors[1]
(that's the doctype for the "Authors" doc, [1] is just for safety) would work for published blog posts, but NOT for new ones - for those, it would point to the root node since now $parent is the "Blog" node and not the "Blog Posts" node.
will work correctly in both cases, since $current may refer to either the blog post (if published) or to its parent (if new thus unpublished), but both will eventually point to pageBlogList (the "Blog" page's doctype) and then go down the hierarchy to the authors folder.
MNTP Xpath $current, $parent point to different node when creating a new node vs editing an existing node
Not sure why I've missed it until now, but I would just like a verification from someone that has already experienced it. I noticed that the context-aware placeholders $current and $parent point to the parent node (and parent-of-parent node respectively) when the node being created is new (i.e. hasn't been published yet).
On the other hand, as soon as the node is published, they point to their respective anticipated locations.
I can guess that happens on creation of a new node because since the node is not published yet, the only close (published) point of reference is its parent - but I'd really like to hear it from someone who's had the same issue. Is that what's supposed to be happening?
I noticed that there have been some references to issues with those placeholders for earlier Umbraco versions but those regarded errors, not behaviour.
For instance:
http://issues.umbraco.org/issue/U4-7602
http://issues.umbraco.org/issue/U4-6243
Hi Sotiris,
Yes, that's "correct" - not really anything to do about it; as you've noticed, it's because the newly created node isn't published and thus not available in the XML tree.
Hope that helps,
/Chriztian
Good to know! I was afraid I was missing something somewhere.
I'll describe the issue I faced below, and how I solved it, hoping it'll help others (also hoping it won't confuse them more :) )
The solution I generally found effective in case, for example, I needed to point to the node's parent by doctype is that I could use
instead of
(assuming that $parent IS of doctype xxx) or
or
or whatever similar
(or any other path including $parent, where xxx is the doctype) to point to to a specific node type upwards in the hierarchy regardless of where $current points to my original node (if it is published) or its parent (if it's new).
For example, I've got a "Blog" folder and under it I've got the following structure:
(I only mentioned the doctypes for the nodes I'm going to use below. )
When I create a new "Post", I have pickers with which I can select an author and one or more categories. The pickers point to the "Categories" and "Authors" documents respectively, each one having its own doctype.
So the xpath query
(that's the doctype for the "Authors" doc, [1] is just for safety) would work for published blog posts, but NOT for new ones - for those, it would point to the root node since now $parent is the "Blog" node and not the "Blog Posts" node.
On the other hand, using
will work correctly in both cases, since $current may refer to either the blog post (if published) or to its parent (if new thus unpublished), but both will eventually point to pageBlogList (the "Blog" page's doctype) and then go down the hierarchy to the authors folder.
I hope I'm making sense :)
Yay - great rundown -- that's exactly how I do it too :-)
/Chriztian
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.