Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Mar 11, 2013 @ 22:39
    Bo Damgaard Mortensen
    0

    MNTP XPath expression using the global setting

    Hi all,

    First off: I'm not sure if this is the correct forum section to ask this question. If not, I'm sorry ;-)

    I'm currently developing an Umbraco solution which contains multiple sites. On some pages, I need to use the Multi-Node Tree Picker datatype to reference some nodes within the context of the current site. The structure is as follows:

    Content
        - Site 1
             - Page 1 (MNTP: Related links)
             - Page 2 (MNTP: Related links)
             - Page 3 (MNTP: Related links)
    
        - Site 2
             - Page 1 (MNTP: Related links)
             - Page 2 (MNTP: Related links)
             - Page 3 (MNTP: Related links)
    

    On the MNTP, I only want to display pages within the respective site branch. The XPath expression is quite easy when setting the MNTP to "From current", however, the downside of this is that the MNTP doesn't know what to render since "current" is not published yet which leads to the "No nodes"-message in the picker tree.

    Is there any way of writing an expression which uses the Global setting in MNTP to display only the branch of current node?

    Any help/hint on this is greatly appreciated since I'm by no means an XSLT expert ;-)

    Thanks in advance,

    Bo

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 11, 2013 @ 22:46
    Chriztian Steinmeier
    1

    Hi Bo,

    When using an XPath, you can use the magic string "$parentPage" to start the expression from the parent of the node you're editing, which should be published...

    Edit: So for example $parentPage/ancestor-or-self::*[@level = 1] to go to the current site's root node

    /Chriztian

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Mar 11, 2013 @ 22:52
    Bo Damgaard Mortensen
    0

    Hi Chriztian,

    Thanks for your input :-) Neat little fix right there! But what happensif parent node is the Content root node then? (Can test tomorrow - lazy-webbin' here ;-))

    Thanks again!

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 11, 2013 @ 22:57
    Chriztian Steinmeier
    0

    Ach so - so you mean if the node being edited is one of the Site nodes?

    Does that make sense in that setup? — it doesn't look like that's possible ...

    /Chriztian

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Mar 11, 2013 @ 23:03
    Bo Damgaard Mortensen
    0

    Yup, there will also be MNTPs on "Site 1" and "Site 2" nodes :-)

    I might need to re-structure the site then, but the site nodes ("Site1" and "Site2") contains different settings for the respective site where MNTPs are used though.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 11, 2013 @ 23:13
    Chriztian Steinmeier
    0

    Allrighty then,

    I don't think you'll need to restructure - just need to know what you're dealing with...

    I'd say you create two MNTP datatypes, one for the Ste nodes and one for the others. On the Site nodes you'll want to use "from current" - and then on the others, use the one I provided earlier. Thing is, if you're on a Site node and it isn't published, then neither of it's children will be published either (guessing they *could* be in some scenario?)...

    - but maybe I'm missing some obvious use case here...?

    /Chriztian 

     

     

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Mar 11, 2013 @ 23:30
    Hendy Racher
    1

    Hi,

    There there is another magic string: $ancestorOrSelf which should do the trick :)

    HTH,

    Hendy

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 11, 2013 @ 23:38
    Chriztian Steinmeier
    0

    Cool Hendy — of course!

    So if we use $ancestorOrSelf/*[@level = 1] it will stop at level 1 even if that one hasn't been published yet?

    /Chriztian

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Mar 12, 2013 @ 00:12
    Bo Damgaard Mortensen
    0

    Hi Hendy and Chriztian,

    I actually had a chat with René from Skybrud.dk today about it. We tried the following:

    $ancestorOrSelf/ancestor-or-self::*/[@isDoc][@level = 1]

    This seems to work on childnodes, but when accessing the Site node (with around ~5 - 6 MNTPs with this expression), the app pool crashes ;-) But I suspect that it's because of some kind og "endless loop" (lack of better word) since we're calling ancestor-or-self two times (?)

    I'll definitely try $ancestorOrSelf/* [@isDoc][@level = 1] tomorrow to see if that makes the difference! :-)

    Thanks again!

    / Bo

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Mar 12, 2013 @ 00:40
    Bo Damgaard Mortensen
    0

    Alright, couldn't control my curiosity. Made a few tests:

    $parentPage/ancestor-or-self::* [@isDoc][@level = 1] actually works on the Site node :-) It also works if the parent node is not published, but only on childnodes which aren't published. On published nodes under the unpublished parent, I get the "[No nodes exists.. ]" message.

    $ancestorOrSelf/* [@isDoc][@level = 1] didn't do anything.

    $ancestorOrSelf/ancestor-or-self::* [@isDoc][@level = 1] works aswell, but all hell is loose if the editor accidently unpublishes the Site node ;-) If the Site node is unpublished, all MNTPs is missing their nodes. Also, if there's a bunch of MNTP's on a node with this expression, it seems to be not-so-performant.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 12, 2013 @ 08:31
    Chriztian Steinmeier
    0

    Hi Bo,

    All of my answers here (and above) assume your Site nodes are at level 1 - but your initial setup description seems to imply that, right?

    If $parentPage/ancestor-or-self::*[@isDoc][@level = 1] works on the Site node there's something not quite logically going on behind the scenes when $parentPage is replaced — maybe Hendy knows what actually happens?

    Using $ancestorOrSelf you would actually have to do this instead: $ancestorOrSelf/self::*[@isDoc][@level = 1] (or $ancestorOrSelf[@isDoc][@level = 1] but that depends a lot on how the actual replacement is done).

    Just a couple more cents from me :-)

    /Chriztian

     

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Mar 12, 2013 @ 15:53
    Bo Damgaard Mortensen
    0

    Hi again Chriztian,

    I tried with the expression you wrote and both of them works :-) However, when the Site node is unpublished, it seems to cause some kind of endless loop which gives a request timeout -/ So when I want to create a new Site node, I get a request timeout because it's unpublished from the start. I guess it's because there are no 'ancestorOrSelf' yet (?)

    Thanks again :-)

    / Bo

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Mar 12, 2013 @ 16:12
    Bo Damgaard Mortensen
    0

    Think I will have to go with two separate MNTPs then :-) One for the Site node which uses "From current" and then the others which uses $ancestorOrSelf.

Please Sign in or register to post replies

Write your reply to:

Draft