In a razor macro I could do next code and get the content root (I traversed the root to get the languages) I know wrong setup but was basically a single language site now we want multilanguage ;)
var contentRoot = Library.NodeById(-1);
So trying to convert everything into views i stumbled upon this thing : I can no longer get to the root.
tried following
var contentRoot = Model.AncesterOrSelf(-1)
var contentRoot = Model.AncesterOrSelf(0)
var contentRoot = Umbraco.TypeContent(-1)
var contentRoot = Umbraco.TypeContent(0)
var contentRoot = Umbraco.Content(-1)
var contentRoot = Umbraco.Content(0)
Anyone have a clue or will i have to harcode the language nodeIds?
Thx for the tip will try it out what i ended up doing was this :
var root = library.GetXmlNodeByXPath("//root");
But I have a feeling I'm using a bug fot this one, because it seems like no matter what xPath i give to library.GetXmlNodeByXPath it always returns the root.
If the following is my content tree and website is displaying page NL/Projecten/Project1 my script will check if this page is available in the other language if not it will try 1 level up and so on. this way i get the closest page in the different language and can diplay a good language selector.
I decided to use it this way because then we can keep existing structure.
So i use xpath to see in my root-var if the current paht is available in the other language like this
var langXPath = "string(//root/langPage[@nodeName='" + lang + "']" + xpath + "/@id)"; var otherLangId = root.Current.Evaluate(langXPath).ToString()
so xpath is a var holding the XPath to the current page (from its language)
The evaluate will give me the id of the node if it exists if not i cut the xPath string and try again I'm at language root.
if i use the same XPath with library.GetXmlNodeByXPath(langXPath) I will still get the complete XML thats why I think its a bug no matter what xpath i give i always get everything.
Root in MVC view
In a razor macro I could do next code and get the content root (I traversed the root to get the languages) I know wrong setup but was basically a single language site now we want multilanguage ;)
var contentRoot = Library.NodeById(-1);
So trying to convert everything into views i stumbled upon this thing : I can no longer get to the root.
tried following
Anyone have a clue or will i have to harcode the language nodeIds?
Hi Koen,
I have the same problem, and no one seem to answer my post also,
I was able to get the root using uQuery by usinh a syntax like this in razor.
var latestNews = umbraco.uQuery.GetNode(-1).GetDescendantNodesByType("NewsItem").OrderByDescending(t => t.CreateDate).ToList();
I do not know if it is the correct way to do it but it worked.
/Tommy
hi Tommy,
Thx for the tip will try it out what i ended up doing was this :
But I have a feeling I'm using a bug fot this one, because it seems like no matter what xPath i give to library.GetXmlNodeByXPath it always returns the root.
If the following is my content tree and website is displaying page NL/Projecten/Project1 my script will check if this page is available in the other language if not it will try 1 level up and so on. this way i get the closest page in the different language and can diplay a good language selector.
I decided to use it this way because then we can keep existing structure.
So i use xpath to see in my root-var if the current paht is available in the other language like this
so xpath is a var holding the XPath to the current page (from its language)
The evaluate will give me the id of the node if it exists if not i cut the xPath string and try again I'm at language root.
if i use the same XPath with library.GetXmlNodeByXPath(langXPath) I will still get the complete XML thats why I think its a bug no matter what xpath i give i always get everything.
So i will have a look at your solutions
thanks
Hi Tommy,
Works out great but intellisense also gave me this option
I know this is ooooold post but if anyone stumbles upon this again then I use
is working on a reply...