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 :-)
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 :-)
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:
When I do:
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:
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
Should be:
Model.XPath("./ancestor-or-self::Site/Frontpage")[0];
Hi Bo,
If Frontpage is the documenttype alias you should do:
To always grab the frontpage in the site you're currently in (Model gives you the equivalent of $currentPage, right?)
/Chriztian
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 !
is working on a reply...