I am working on a multilingual website and i need to extract Siblings of a root node with razor code to match language name/rootnode name with browser language.
@{ @* Get value of UserLanguages from HttpContext Object This is Browser Language Setting This is returned as an array, as it can have more than one language The first value in the arrary is the default or preferred language Value is returned as language-culture (eg en-gb), so we might need to trim to just get language code *@ var contentRoot = Model.AncestorOrSelf(1);
var lang = System.Web.HttpContext.Current.Request.UserLanguages[0]; <div>@lang</div> var langName = lang.ToString().Substring(0, 2); var nodeName = Model.Name; var sibs = Model.AncestorOrSelf().Descendants("umbHomePage").Items;
once i get all the sibling node names(my node names are like en, her, fr, da etc.,) then i will write a condition if var itemNode.Name equals to langName then redirect to that language home page.
Siblings of a rootnode in the Content
Hi
I am working on a multilingual website and i need to extract Siblings of a root node with razor code to match language name/rootnode name with browser language.
Thanks,
Lasya.
I have tried like this
var sibs = Model.AncestorOrSelf().Descendants("umbHomePage").Items;
<ul>
@foreach (var itemNode in sibs)
{
<li><a href="@itemNode.Url">@itemNode.Name</a></li>
}
</ul>
and
var sibs = Model.AncestorOrSelf(1).Siblings("umbHomePage");
<ul>
@foreach (var itemNode in sibs)
{
<li><a href="@itemNode.Url">@itemNode.Name</a></li>
}
</ul>
But no use.
Thanks,
Lasya
Try this
Hi Fuji
It is throwing an error
Error loading MacroEngine script(file: DetectLanguage.cshtml)
thnks,
Lakshmi.
Hi Laskmi,
Can you please post your full code ?
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
@*
Get value of UserLanguages from HttpContext Object
This is Browser Language Setting
This is returned as an array, as it can have more than one language
The first value in the arrary is the default or preferred language
Value is returned as language-culture (eg en-gb), so we might need to trim to just get language code
*@
var contentRoot = Model.AncestorOrSelf(1);
var lang = System.Web.HttpContext.Current.Request.UserLanguages[0];
<div>@lang</div>
var langName = lang.ToString().Substring(0, 2);
var nodeName = Model.Name;
var sibs = Model.AncestorOrSelf().Descendants("umbHomePage").Items;
}
<ul>
@foreach (var itemNode in sibs)
{
<li><a href="@itemNode.Url">@itemNode.Name</a></li>
}
</ul>
this is my code
once i get all the sibling node names(my node names are like en, her, fr, da etc.,) then i will write a condition if var itemNode.Name equals to langName then redirect to that language home page.
Thanks
Hello
Any help to get Root node siblings with razor script Please.
Thanks
Hi Lasya,
Let me get this right, you are working with a multilingual website right ?
If you have this following structure under the Content section
Content
- En
-- Item 1
-- Item 2
- Fr
-- Item 1
-- item 2
- Da
-- Item 1
-- Item 2
your script will automatically pick the content and display the Urls and Name of the content depending on the language you are.
What do you get if you do something like thise
/Fuji
Replace the docType with the documentType name of the nodes you want to display
Hi Fuji
I have tried your code and not displaying anything.
I want to get my language nodes/homepages which are at level 1. en, fr, da, hr etc.,
and i have dropped my razor macro in my home page template(i.e en node template).
Thanks
Hi Laysa,
I had the same problem. I resolved the problem by looking at the different home pages based on the document type like this.
I hope this helps!
Kind Regards, Gert.
is working on a reply...