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
    Sep 10, 2012 @ 01:18
    Bo Damgaard Mortensen
    0

    Model.XPath multilingual site

    Hi all,

    I'm wondering how I can use the Model.XPath method to get a reference to the root node (followed by descendant nodes) in a multilingual setup where there's a site for each language, like this:

    Content
        - da
            - Forside
    
        - en
            - Frontpage

    When I do:

    var frontpage = Model.XPath("//Frontpage");

    I always get the first node of type "Frontpage", the danish one, even though I'm on the english website.

    Is there any way to express that it's the root node of the *current page* instead of just going to the first rootnode available?

    Also, is there any equivalent way of doing this in "pure" Razor where the performance is on par with an XPath expression? Something like:

    var frontpage = Model.AncestorOrSelf().Site.Frontpage.First();

    Will the above query perform just as well as the XPath?

    Simply trying to get my head around any performance fallpits in Razor here since the site I'm developing spikes at ~9k visitors a day in specific months of the year :-)

    Any inputs on this is greatly appreciated!

    Thanks in advance,

    Bo

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Sep 10, 2012 @ 01:24
    Bo Damgaard Mortensen
    0
    var frontpage =Model.AncestorOrSelf().Site.Frontpage.First();

    Should be:

    var frontpage =Model.AncestorOrSelf().Frontpage.First();
  • Paul Mieczkowski 6 posts 52 karma points
    Sep 10, 2012 @ 11:59
    Paul Mieczkowski
    0

    Model.XPath("./ancestor-or-self::Site/Frontpage")[0];

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Sep 10, 2012 @ 12:28
    Chriztian Steinmeier
    0

    Hi Bo,

    If Frontpage is the documenttype alias you should do:

    Model.XPath("ancestor-or-self::Frontpage")

    To always grab the frontpage in the site you're currently in (Model gives you the equivalent of $currentPage, right?)

    /Chriztian

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Sep 10, 2012 @ 12:35
    Bo Damgaard Mortensen
    0

    Hi Chriztian and Paul,

    Thanks for your input, it works great :-) Still curious if this could be written in a more Razor-like way instead of going the (über fast) XPath route, been fooling around with the thought of just writing it in XSLT.

    Oh, and yes - Model is equivalent to $currentPage :-)

    Thanks again !

Please Sign in or register to post replies

Write your reply to:

Draft