Copied to clipboard

Flag this post as spam?

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


  • Luke 110 posts 256 karma points
    Jun 16, 2015 @ 19:13
    Luke
    0

    XPath In Razor Macro

    Hello All,

    I am trying to retrieve the relevant node in a macro with the method:

    Umbraco.ContentSingleAtXPath
    

    The idea is that a get the node relevant to the CurrentPage - so for example:

    Umbraco.ContentSingleAtXPath("ancestor-or-self::LandingPage")
    

    However this does not seem to be working - can anybody help please?

    Regards, L

  • Luke 110 posts 256 karma points
    Jun 17, 2015 @ 10:41
    Luke
    0

    Anybody who can help it would be warmly appreciated as I am desperate.

    Regards, L

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Jun 17, 2015 @ 13:47
    Tim
    0

    You could do this in pure Razor, no need for XPath. Try:

    Model.Content.AncestorOrSelf("LandingPage")
    

    That should give you the page you're after, relative to the current page.

  • Luke 110 posts 256 karma points
    Jun 17, 2015 @ 16:07
    Luke
    0

    Hi Tim,

    Thank you - but I need it to be dynamic as I do not know what the path will be as this will be entered by the user. As such it may be descendants, ancestors, etc. It is for this reason that I was looking at XPath.

    Regards, L

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Jun 18, 2015 @ 08:58
    Tim
    0

    I don't know if it'll work in this context, but you could try using the $currentPage token in your XPath? That should grab the current node, but I don't know if it works in the Umbraco helper.

  • Luke 110 posts 256 karma points
    Jun 19, 2015 @ 13:12
    Luke
    0

    Hi Tim,

    Thanks - but $currentPage does not work in Razor script. I have access to the CurrentPage but not sure how I could use this.

    I know it must be possible as Umbraco Forms uses the current node as Current Page when specifying an XPath.

    Hope someone can maybe add to this??

    Regards, L

Please Sign in or register to post replies

Write your reply to:

Draft